I've got img tag in my text and I want to get the name of the file from src
So I use this code
preg_match_all("|\/img\/(.*)\/>|U", $article_header, $matches, PREG_PATTERN_ORDER);
echo "match=".$matches[1][0]."<br/>";
Doing so I get this as a result
match=500.JPG\" alt=\"\" width=\"500\" height=\"360\"
So in this case I use "\/>" which means the end of tag.
But I want only name of the file "500.JPG" So I must use "\" but when I do it
preg_match_all("|\/img\/(.*)\\|U", $article_header, $matches, PREG_PATTERN_ORDER);
I get no matches :( Please help
With the help of yes123 I did this
$doc = new DOMDocument();
$doc->loadHTML($article_header);
$imgs = $doc->getElementsByTagName('img');
$img_src = array();
foreach ($imgs as $img) {
// Store the img src
$img_src[] = $img->getAttribute('src');
echo $img_src[0];
}
which gives me this
\"sources/public/users/qqqqqq/articles/2011-06-11/7/img/500.JPG\"
But now anyway I want only 500.JPG from this
So what is the right regexp ?