How does php obtain the content in the title of a webpage through the address. For example, I enter a URL in the text box. Click "get title" to obtain the title and write it to the text box below.
Reply to discussion (solution)
$arr = file("http://bbs.csdn.net/topics/390516454");if($arr){foreach($arr as $a){if(strchr($a,"")){$a = str_ireplace("<title>","",$a);$a = str_ireplace("","",$a);echo $a;break;}}}
How does php obtain the content in the title of a webpage through the address. -CSDN forum-CSDN. NET
================================
Not a reliable method. but in most cases
Capture the page and parse the title
$arr = file("http://bbs.csdn.net/topics/390516454");if($arr){foreach($arr as $a){if(strchr($a,"")){$a = str_ireplace("<title>","",$a);$a = str_ireplace("","",$a);echo $a;break;}}}
How does php obtain the content in the title of a webpage through the address. -CSDN forum-CSDN. NET
================================
Not a reliable method. but in most cases
If your website is changed to Baidu, there is a problem ..
Let's talk about the idea and complete the code by yourself.
Ajax transfers values to php, php collects the title and returns it to ajax, and then js writes it to the input box.
Let's talk about the idea and complete the code by yourself.
Ajax transfers values to php, php collects the title and returns it to ajax, and then js writes it to the input box.
Another problem is that some websites are gbk, some are utf8, so how can I ensure it is not messy?
$arr = file("http://bbs.csdn.net/topics/390516454");if($arr){foreach($arr as $a){if(strchr($a,"")){$a = str_ireplace("<title>","",$a);$a = str_ireplace("","",$a);echo $a;break;}}}
How does php obtain the content in the title of a webpage through the address. -CSDN forum-CSDN. NET
================================
Not a reliable method. but in most cases
If your website is changed to Baidu, there is a problem ..
$arr = file("http://www.baidu.com/s?wd=mysql+%B8%B4%D6%C6%BC%C7%C2%BC");if($arr){foreach($arr as $a){if(strchr($a,"")){$n1 = strpos($a,"<title>")+7;$n2 = strpos($a,"");$a = substr($a,$n1,$n2-$n1);echo $a;break;}}}
It's better to replace with regular expressions, so I don't have to use this stupid method.
Let's talk about the idea and complete the code by yourself.
Ajax transfers values to php, php collects the title and returns it to ajax, and then js writes it to the input box.
Another problem is that some websites are gbk, some are utf8, so how can I ensure it is not messy?
Garbled reference http://www.cnblogs.com/rosenia/archive/2013/05/20/3088146.html
Convert to the format output of your website.