php - Replace HTML entities between divs and only between divs -
given following string:
asd <div> def foo </div> ghi <div> moo </div> i want remove of 's within <div>s, resulting in:
asd <div> def foo </div> ghi <div> moo </div> i can use standard php stuff, i'm not sure how approach problem. couldn't figure out how keep contents inside <div>s while removing
the reason why need because wordpress's content filter adds under strange situations. can't remove because might've been entered user, need remove of them within element that's having display problems caused them
the following works in case:
$str = "asd <div> def </div> ghi <div> moo </div>"; $res = preg_replace("%<div>(.*?) (.*?)</div>%", "<div>$1$2</div>", $str); but beware of facts:
- it won't work if divs have attributes;
- it won't work expected if divs nested;
- it applies replacement of
1 time, multiple s inside divs untouched.
so abovementioned replacement not solution @ all. it's way better first find div tags (xml) parser function , replace s.
Comments
Post a Comment