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 inpattern
. - 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\>/" ,$str,$title); return $title[1]; } } //Example: echo getTitle("http://www.example.com"); ?>
OUTPUT
Own Tutorials - Teach Your Self
No comments:
Post a Comment