How to add HTML tags in front of every character that is part of the regular expression syntax in PHP

1 Answer

0 votes
$s = "This *PHP* code is nice";
$word = "*PHP*";
$s = preg_replace("/" . preg_quote($word, '/') . "/", "<i>" . $word . "</i>", $s);
                          
echo $s;


/*
run:
    
This *PHP* code is nice 

       
*/

 



answered Jul 15, 2016 by avibootz
...