LoginSignup
0
0

More than 5 years have passed since last update.

Get Image Tag From a String

Posted at

The code below can get the img tag from a static string, like this :

/img/portrait.gif?t=1451961935000" align="absmiddle
http://www.example.com/ssss.jpg

function Allimg($str)
{
    $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/";
    preg_match_all($pattern, $str, $match);
    $_count = count($match[1]);
    $_html = '';
    if ($_count>0) {
        for ($i = 0; $i < $_count; $i++) {
            $_html = $_html . $match[1][$i];
            $_html = $_html . '<br>';
        }
    }
    return $_html;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0