[PBNL] Crawl Out The First Occurence Image Url In A Post And Use it to at Featured Links Like Netnaija.

With the Aid Of this Function, you can Crawl Out the First Occurence Image Url.

If a post Contain

[PBNL] Crawl Out The First Occurence Image Url In A Post And Use it to at Featured Links Like Netnaija.
as the post image link,this Function wil crawl it out negleting the [img] and [/img] bbcode.

Xo it wil be nw become this http://netnaija.com/images/featured/analike-the-baddo-of-destiney.png
xo u can use it at ur exclusive update in ur web lyk NetNaija


Code
<?php
function first_img($text,$thumb) {
global $config;
$res = preg_match('#\[img\](.*?)\[\/img\]#is', $text, $matches);
if (!$thumb == '') $text = '<img src="'.$thumb.'" width="48" height="48">';
elseif(!$matches[1] == '') $text = '<img src="'.$matches[1].'" width="48" height="48">';
else $text = '<img src="'.$config->url.'/images/none.png" width="48" height="48">';
return $text;
}
?>

If deres no Image Found In the Post, it wil return default img, xo change the /images/none.png to ur default image link

Now,
fetch the post content and rap it wit the abv function to get the image link
i.e

Code
<?php
$post_content = $info["message"]; $change_tags=preg_replace('#<img(.*?)src="(.*?)"(.*?)>#is','[img]\\2[/img]',$post_content);
$img_first = first_img($change_tags,$post_content = NULL);
?>

And Insert $img_first into ur b_updates. For u to b able to do dis..kindly create a column in ur b_updates named `img`

Code
<?php
ERROR_REPORTING(0);
 
include("init.php");
$query=mysql_query("ALTER TABLE `b_updates` ADD `img` varchar(255) NOT NULL");
if(!$query){
header("location: index.php?msg=error");
} else {
header("location: index.php?msg=success");
}
?>

save as img.php and install...

Goto ur func.php,fetch along the img row and print or echo am as desired. Complicated? Drop Comment below.. Ama reply u

Comments

Keep up to date with our latest articles and uploads...