3v4l.org

run code in 300+ PHP versions simultaneously
<?php $searchArray = array('settings all','print', 'sum', 'industry'); // total 50K words function sanitize($string,$searchArray) { $repl = array_map("dashReplace", $searchArray); $pattern = array_map("insertWordBoundaries", $searchArray); $string = preg_replace($pattern,$repl,$string); return $string; } function dashReplace($str) { return "<span class='txtOlg'>" . $str . "</span>"; } function insertWordBoundaries($str){ return "/\b". preg_quote($str,"/") ."\b/"; } $text = 'Lorem Ipsum is simply dummy text of the printing and typesettings all industry.'; echo sanitize($text,$searchArray);

preferences:
24.55 ms | 406 KiB | 5 Q