Do not replace anything when inside a html tag. Preg Regex
I have this regular expression:
$buffer = preg_replace("/'([a-zA-Z0-9]+)开发者_C百科'/iU",'$1',$buffer);
It removes single quotes when there's no whitespace between the quotes. I also replaces inside a html tag. I don't want it to do so.
Here's an example
<div id="Foo"></div>
Should be:
<div id=Foo></div>
And
<script>Foo='Bar'</script>
Should not change and therefore be:
<script>Foo='Bar'</script>
HTML is unpredictable, and cannot be accurately handled with regular expressions. Unless you created the HTML and can be very, very certain of its exact format, use an HTML parser. Even if you can, the HTML parser is probably far easier to use, anyway.
Sorry :/
精彩评论