Sublime Forum

PHP Open Close match

#1

Hello,

Question about BracketHighlighter ( i hope so i can ask here about external plugins :grimacing: ) or Sublime native option

Is it possible to highlight the match PHP Open and Close Tag?

Example like this:

PS. —> Maybe Sublime have native option for foreground color or something like this?

0 Likes

#2

BracketHighlighter does that. But its PHP tag matching is not enabled for PHP by deault. (It’s enabled for HTML by default somehow)

0 Likes

#3

Thanks for quick answer. Could you tell me how can i turn on that? I did not find a solution in HB documentation :frowning:

0 Likes

#4

That’s in its package default settings. You just have to copy that and add PHP into the language_list in your BH user settings.

        // PHP Angle
        {
            "name": "php_angle",
            "open": "(<\\?)(?:php)?",
            "close": "(\\?>)",
            "style": "angle",
            "scope_exclude": ["string", "comment", "keyword.operator"],
            "language_filter": "whitelist",
            "language_list": ["HTML", "HTML 5"], // PHP is not listed here somehow :confused: 
            "enabled": true
        },
0 Likes

#5

Works, but if you have syntax like that:

<?php while ($row = mysqli_fetch_array($results)) { ?>
    <div>Something</div>
<?php } ?>

is matching error:

Any solution for this?

0 Likes

#6

This is a known issue with BracketHighlighter. Essentially you are mixing two different languages, one that is meant to be processed before the other. PHP in an HTML file is essentially like having preprocessor statements in other languages.

BracketHighlighter doesn’t have multi staged bracket detection: preprocessor step and then a normal step. Brackets are all evaluated at the same time. So when you have <?php { ?> <?php } ?> It is essentially like saying this to BracketHighlighter [ ( ][ ) ] It knows it needs to match both [] and (), but the setup is nonsense to BracketHighlighter. It sees, and tries to resolve (), but it can’t since the opening is enclosed in one [] and the closing is enclosed in another []. BracketHighlighter sees this and says “something is really wrong” and it aborts. This is why PHP stuff is disabled by default in HTML. It just doesn’t handle it well.

4 Likes

#7

Ok, now it’s all clear for me. Thank you guys

0 Likes