php - Regex to extract specific urls from <img> tags in an HTML document -


i trying extract specific url pattern body of content , replace newly formed url. running problems regex patterns , wanted see if me.

here code testing with:

$body = '<p><img src="/file/637/view" height="540" width="640"></p>'; $pattern = '/src="/file/(0-9)+/view"/'; $pattern = '/src="/file/(.)+/view"/'; $pattern = '/"/file/[0-9]+/view"'; $pattern = '/\<img src="(.)+"(.)+"\>/';  preg_match($pattern, $body, $matches); 

now, last pattern down grab entire image tag, great, want extract image urls (just url) use "/file/(some number)/view" pattern can form new urls , string replace on them. of others fail find when run print_r on $matches var.

obviously body string represents content body scanning this. suggestions how work , grab image url? have work situations multiple images intermingled lots of other html including anchor tags.

try replace (.) (.*?) or problem, try following

$body = '<p><img src="/file/637/view" height="540" width="640"></p>'; $pattern = '/\/file\/([0-9]+)\/view/';   preg_match($pattern, $body, $matches); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -