SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

Highlight String in PHP

       

Function for highlighting text/strings in PHP.


$content = file_get_contents("http://php.net/");

print highlight("PHP", $content);

function highlight($match, $string){ return str_ireplace($match, "<span style='background:yellow'>$match</span>", $string); }

Will output something like this [caption id="" align="alignnone" width="345" caption="Highlighted PHP.Net"]Highlighted PHP.Net[/caption]

***Notice all the styles are gone :( ... would need to parse the document body to maintain stylesheet and other 'php' strings that might be in resources paths.

Tagged w/ #file_get_contents #highlight #phpphp

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app