I use the following code for replacing matched words within a String:
- for ($i=0; $i < count($terms); $i++) {
- if ( $terms[$i] == '' || $terms[$i] == ' ' || strlen($terms[$i])==0 ) continue;
- $searchingFor = "/" . $terms[$i] . "/i";
- $replacePattern = "<strong>$0</strong>";
- $result['titulo'] = preg_replace($searchingFor, $replacePattern, $result['title']);
- }
- echo $result['title'];
Where 'terms' is an Array from $_GET['terms'].
All works fine except when user input strings containing characters like slashes. It arise an exception in preg_replace.
How can i solve this issue?
Thanks.