php - Get image url from content containing an image -


i building small cms system personal use. part of requires me first image url in article. how can this?

sample article content in variable $article

<p> <img src="/images/usercontent/2013-07-12%2022_27_34.png"> griefing problem has been curbed! </p> 

how can url /images/usercontent/2013-07-12%2022_27_34.png
possibly regex? if yes, how? clueless regex

use domdocument class:

<?php     $myhtml = '...'     $doc = new domdocument();     $doc->loadhtml($myhtml);     $imagetags = $doc->getelementsbytagname('img');      foreach($imagetags $tag) {         echo $tag->getattribute('src');     } ?> 

output:

/images/usercontent/2013-07-12%2022_27_34.png 

working demo!


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -