I need to get proper image for each article. Every single image is saved among different HTML tags in different rows in database. So how should I get img URL with PHP code?
<p><img src="images/akhbar/5/q103.jpg" alt="q103" style="display: block; margin-left: auto; margin-right: auto;" height="315" width="675" /></p>
<p> Who is Sara Bareilles on Sing Off</p>
thanks for your answers.i could solve my problem with this code.hope help other guys.
$text = $row["your html text from database row"];
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $text, $img);
$pics=$img[1];
output is ($pics)= ( images/akhbar/5/q103.jpg )
Well I am not good at regex-ing but I did give it a try. Check this if it works.
$str="<p><img src='sfd;lfjnglsmsfd.jpg' />"; //This is where you pass that column value
$del="src=";
$pos=strpos($str, $del);
$important=substr($str, $pos+strlen($del), strlen($str)-1);
$pos2=strpos($important, ".jpg");
$final = substr($important, 0, $pos2);
$final = str_replace("'", "", $final);
return $url = $final.".jpg";