help me to get link title

Started on the old forum in July 2012 · view the original in the archive · old links redirect here

2 replies · 530 views · started 14 years ago · 1 min read

3 participants
borobari Newbie · 1 posts #1

this is my php code please anyone add here when some one post a link automatically get link title like Facebook

<?
function img_preg($arr)
{
return '<img src="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[1])).'" alt="img" />';
}
function links_preg1($arr)
{
global $set;
if (ereg('^http://'.$_SERVER['HTTP_HOST'],$arr[1]) || !ereg('://',$arr[1]))
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
else
return '<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[1])).'">'.$arr[2].'</a>';
}
function links_preg2($arr)
{
global $set;
if (ereg('^http://'.$_SERVER['HTTP_HOST'],$arr[2]))
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
else
return $arr[1].'<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[2])).'">'.$arr[2].'</a>'.$arr[4];
}
function links($msg)
{
global $set;
if ($set['bb_img'])$msg=preg_replace_callback('/\[img\](.+)\[\/img\]/isU', 'img_preg', $msg);
if ($set['bb_url'])$msg=preg_replace_callback('/\[url=(.+)\](.+)\[\/url\]/isU', 'links_preg1', $msg); 
if ($set['bb_http'])$msg=preg_replace_callback('~(^|\s)([a-z]+://([^ \r\n\t`\'"]+))(\s|$)~iu', 'links_preg2', $msg);
return $msg;
}

?>
something else Fellow · 2,296 posts #2

use the search function you will find your answer

GumSlone Administrator Principal · 1,690 posts #3
$site_url = $_REQUEST['site_url'];
	if(filter_var($site_url, FILTER_VALIDATE_URL))
	{
		$html = file_get_contents($site_url);
		if(!empty($html))
		{
			//parsing begins here:
			$doc = new DOMDocument();
			@$doc->loadHTML($html);
			$nodes = $doc->getElementsByTagName('title');
			
			//get and display what you need:
			$tags['title'] = $nodes->item(0)->nodeValue;
			if(empty($tags['title']))
			{
				$parse = parse_url($site_url);
				$tags['title'] = $parse['host'];
			}
			$metas = $doc->getElementsByTagName('meta');
			
			for ($i = 0; $i < $metas->length; $i++)
			{
				$meta = $metas->item($i);
				if($meta->getAttribute('name') == 'description')
						$tags['description'] = $meta->getAttribute('content');
				if($meta->getAttribute('name') == 'keywords')
						$tags['keywords'] = $meta->getAttribute('content');
			}
		}
	}

print_r($tags);

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close