regex - Bold matched text in a String in PHP -
I use the following code to change the matched words within the string:
For ($ I = 0; $ i & lt; Count ($ word); $ i ++) {if ($ word [$ i] == '' || $ word [$ i] == '' || strlen ($ word [$ I]) == 0) released; $ Searchfor = "/" $ word [$ i] "/ i"; $ Replacement = "& lt; strong> $ 0 "; $ Result ['titulo'] = preg_replace ($ for search, $ location pattern, $ result ['title']); } Echo $ result ['title'];
Where 'conditions' is an array from $ _GET ['rule'].
Correct all the tasks, when user input characters are letters like slash
thanks.
itemprop = "text">
Use:
$ SearchFor = "/" Preg_quote ($ word [$ i], "/") "/ i";
Preg syntax (. \ + * [[]] Before all the characters used in $ () {} =! This function is used for a backslash
\ < Code / code>. & Lt;> | :: -
) and before all the characters in the second argument, used here to avoid their delimiter character /
goes.
Comments
Post a Comment