html - PHP regex pattern not identifying closing bracket for tag -
html - PHP regex pattern not identifying closing bracket for tag -
i have text area of text can perchance contain tags in them. need identify these tags specific string of text in src attribute ("/storyimages/") , delete them. instance, if have text
<br><img src="/storyimages/myimage.jpg" align="right" width="105" height="131"><b>(cns) </b>lorem ipsum dolor... i want rid of whole tag , replace ''. regex pattern i'm trying utilize
/<img src=.*\/storyimages\/.*>/ but it's not working. happens identifies start of string ok, it's not identifying closing > character, if utilize preg_match(), match starts .
i know you're not supposed utilize regex on html, isn't embedded tags; it's 1 tag in midst of bunch of text, should ok. can see, > isn't special character, if escape it, still same result.
is there simple i'm missing create work? or need write sort of function loops on string character character find positions of open , close brackets , replace them?
the interesting thing when seek regex tester, works fine, when run code, problem described above.
thanks.
use <img src=.*?\/storyimages\/.*?> regex.
the main point using *? quanitifier create matching non-greedy (i.e. match to the lowest degree matching characters possible).
here sample php code:
$re = "/<img src=.*?\\/storyimages\\/.*?>/"; $str = "<br><img src=\"/storyimages/myimage.jpg\" align=\"right\" width=\"105\" height=\"131\"><b>(cns) </b>lorem ipsum dolor..."; preg_match($re, $str, $matches); the match <img src="/storyimages/myimage.jpg" align="right" width="105" height="131">.
php html regex
Comments
Post a Comment