Tutorial :how to convert ereg_replace in clean MS Word function to preg_replace?



Question:

I found this function to clean MS Word markup:

$html = ereg_replace("<(/)?(font|span|del|ins)[^>]*>","",$html);  $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>","<\\1>",$html);  $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>","<\\1>",$html);  

and it works fine. However, I would like to replace ereg_replace (deprecated) by preg_replace. When I do this (with / delimiters), the function doesn't work anymore.

I understand very little of regular expressions, I'm afraid... Some wizard here that can help me with this? It would be very much appreciated!!


Solution:1

Try using # as delimiter, example:

$html = preg_replace("#<(/)?(font|span|del|ins)[^>]*>#","",$html);  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »