Search code examples
phpidephpstorm

How to disable code highlighting in PhpStorm?


I started coding in PHP on PhpStorm and I have this permanent highlight that bothers me and I can't find how to turn it off.

Highlighting in PhpStorm

I just search on internet but find nothing specific. Do you know how to do it ?


Solution

  • Rather than doing one long print, PHP developers usually do something like close the PHP tag early with a curly bracket open such as:

    <?php foreach($items as $item) { ?>
        <div>
            <h1>
                <?= htmlspecialchars($item['title'], ENT_QUOTES | ENT_HTML5) ?>
            </h1>
        </div>
    <?php } ?>
    

    Then you'd use another PHP tag to end the open curly bracket.

    I should also comment that HTML Id's should not contain spaces: https://html.spec.whatwg.org/multipage/dom.html#global-attributes:the-id-attribute

    When specified on HTML elements, the id attribute value must be unique amongst all the IDs in the element's tree and must contain at least one character. The value must not contain any ASCII whitespace.

    (emphasis mine)

    For instances where you don't want to print it immediately, and instead get it back as a string, you can use the same approach in combination with output buffering, by surrounding it with ob_start() and ob_get_clean()