PHP get image path from text


Is it possible to get image path from some text using PHP ?
For example, we have a text with such code somewhere inside it This text is stored in DB (as article). How to get image path (in this example it is – http://tutorialspots.com/wp-content/uploads/2013/04/1.png) from text? Of course, text and images varies from article to article
Use Regular Expressions in PHP , we can do it:

<?php
$text = '<img src="myimage.jpg"/>';
if((bool)preg_match('#<img[^>]+src=[\'"]([^\'"]+)[\'"]#', $text, $matches))
{
   print_r($matches);
}
else
{
   echo 'Not found';
}
?>

Leave a Reply