用php中的src属性替换字符串中的图像标签

I want to replace the image tags in the string with their src attributes respectively....

I have this code

$url='<img class="emojioneemoji" src="http://localhost/sng/assets/js/plugins/em/2.1.4/assets/png/1f602.png">checking<img class="emojioneemoji" src="http://localhost/sng/assets/js/plugins/em/2.1.4/assets/png/1f601.png">now<img class="emojioneemoji" src="http://localhost/sng/assets/js/plugins/em/2.1.4/assets/png/1f62c.png"><img class="emojioneemoji" src="http://localhost/sng/assets/js/plugins/em/2.1.4/assets/png/1f600.png">';
$doc = new DOMDocument();
@$doc->loadHTML($url);

$tags = $doc->getElementsByTagName('img');

foreach ($tags as $tag) {
 $img_path =  $tag->getAttribute('src');
 $directory = $img_path;
 $ee = pathinfo($directory);
 $pic_name=  $ee['basename'];
 preg_replace("/<img[^>]+\>/i", " ", $pic_name);
}
echo $url;
?>

I want to get output like this:

-1f602.png-checking-1f601.png-now-1f62c.png-1f600.png-

You could try something like this :

$str = "-" ;
foreach ($tags as $tag) {
    $img_path =  $tag->getAttribute('src');
    $directory = $img_path;
    $ee = pathinfo($directory);
    $pic_name=  $ee['basename'];

    // Get the next element if exists and is a DOMText :
    $next = "" ;
    if ($tag->nextSibling && get_class($tag->nextSibling) == "DOMText") {
        $next = $tag->nextSibling->wholeText . "-" ;
    }

    $str .= $pic_name . "-" . $next ;
}

echo $str ;

Will outputs :

-1f602.png-checking-1f601.png-now-1f62c.png-1f600.png-