You want to show a brief description of an article along with the image which is contain in it article.
You can see what I mean as shown below;
In that case, you don't need to create a new field contain an image in it. You just need to parse the img tag.
This is the code:
private static function getImageInPost($post_content)
$jum = preg_match_all('/src="([^"]*)"/', $post_content,$matches);
foreach ($matches as $match)
if(strpos($match, "src")!== false)
$res = explode("\"", $match);
$image = "<img src='".$res."'>";
$image = "";
Above code returning first image in the article.
Tidak ada komentar: