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
Comments
Post a Comment