Re: Syntax highlighting of odd language
| From: | Aaron Gould | Date: | Mon, 08 Nov 2004 14:59:19 +0000 |
| Subject: | Re: Syntax highlighting of odd language | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201534@lists.php.net to get a copy of this message | ||
M. Sokolewicz wrote:
Now, the problem with such a "solution" is the following. Imagine you have the following keywords: include require in of typof now, when you replace include with <span class="highlighted">include</span>, it'll go on, and also replace all instances of in, so you'll end up with things like <span class="highlighted"><span class="highlighted">in</span>clude</span> (very ugly).I did encounter this during some experimenting. I figured I'd just sort the array of commands from from shortest strong to longest string. But like you said, far too many embedded <span> tags would result!
*a* way to get around that is by using word boundries around the keyword to be replaced (eg. preg_replace('\(\W|^)+('.$highlight[$i].')(\W|$)\i', '$1<span class="highlight">$2</span>$3') )My regular expression skills are very basic, but I understand the gist of your preg_replace statement. Now I just need to polish my regex knowledge! Thanks, -- Aaron Gould Parts Canada - Web Developer