Get Website Title via Link PHP

Sunday 27 October 2013


Get website title via link php

Get Website Title via Link PHP:

  • To get website title using php you have to use some builtin functions
  • First function is file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
  • Second fucntion is preg_match() Searches subject for a match to the regular expression given in pattern.
  • int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
  • If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call.
For example, upon submitting the URL
somesite.com
return

Video Tutorials | Own Tutorials

Try The Following Example:

//$Url is where you we put your own url which you want the title.
function getTitle($Url){
//file_get_contents is a predefine function in php.
//its used for to get all content of a url
    $str = file_get_contents($Url);
    if(strlen($str)>0){
//here preg_match is a predefien function which exactly,
match the given attribute using escape sequence.
        preg_match("/\(.*)\<\/title\>/"</span>,$str,$title);
        <span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; color: rgb(51, 102, 255); background-position: initial initial; background-repeat: initial initial;">return</span> $title[<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; color: rgb(255, 0, 0); background-position: initial initial; background-repeat: initial initial;">1</span>];
    }
}
<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; color: rgb(128, 128, 128); background-position: initial initial; background-repeat: initial initial;">//Example:</span>
echo getTitle(<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; color: rgb(255, 0, 0); background-position: initial initial; background-repeat: initial initial;">"http://www.example.com"</span>);

<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; color: rgb(128, 0, 0); background-position: initial initial; background-repeat: initial initial;">?></span></code></pre>
</blockquote>
<h3 style="margin: 0px; padding: 0px 0px 5px; border: 0px; outline: 0px; font-size: 22px; vertical-align: baseline; color: rgb(72, 66, 63); letter-spacing: -1px; line-height: 1em; font-weight: normal; font-family: 'Droid Sans', Arial, sans-serif;">
<strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 22.22222328186035px; vertical-align: baseline; color: rgb(28, 28, 28);">OUTPUT<br></strong></h3>
<blockquote style="margin: 1.5em; padding: 1em; border: 1px solid rgb(220, 220, 220); outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: rgb(230, 230, 230); quotes: none; color: rgb(102, 102, 102); font-style: italic; font-family: 'Droid Sans', Arial, sans-serif; line-height: 20px;">
<pre style="margin-bottom: 10px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; font-family: 'Courier New', monospace;"><code style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent; font-family: 'Courier New', monospace; background-position: initial initial; background-repeat: initial initial;"><em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.222222328186035px; vertical-align: baseline; background-color: transparent;">Own Tutorials</em> - Teach Your Self</code></pre>
</blockquote>
</div>

No comments:

Post a Comment

 

Total Pageviews

Blogroll

Most Reading