I need to find the first image tag in a MySQL query, in a field called html (containing the HTML of the blog post. Here is the query and while loop I am using...
$query = mysqli_query($dbleads, "SELECT title, html FROM plugin_blog ORDER BY date_added DESC");
while ($row=mysqli_fetch_array($query)){
$i = 1;
$i++;
?>
<!-- echo $row['title'] to be replaced with first image tag in html column -->
<div class="masonryImage" style="width: 300px; height:250px;"> <? echo $row['title']; ?></div> <?
if ($i%2 == 0) { ?>
<div class="masonryImage tweets" style="width:300px; height:175px;"><div class="tweet-content"><? echo $value['text']; ?></div></div>
<?
}
}
// extra parentesis from previous loop from Twitter, meant to be here
}
I am thinking something like preg_match('/(<img[^>]+>)/i', $str, $matches)
, as found from this question, however, not sure how to implement it in this database query.
Thanks!