Search code examples
phpstorm

PhpStorm - Why does the highlighting of the html syntax in the string during the concatenation turn off? How to fix?


There is such a line. HTML in it is highlighted:

echo '<input value="1"/>';

But if you write like this, then the highlighting turn off:

$value = 1;
echo '<input value="'.$value.'"/>';

How to fix?


Solution

  • As @axiac, mentionned, it can only work if there's a single string.

    You can make use of PHP's heredoc syntax, along with variable interpolation:

    echo <<<HTML
    <input value="{$value}" />
    HTML;
    
    // Rest of your code
    

    Or you could just close your PHP tag, display your HTML without echo and then open it again (if you need to):

    <?php
    $value = 1;
    ?>
    
    <input value="<?= $value ?>" />
    
    <?php
    // Rest of your code