How does php obtain the content in the title of a webpage through the address.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.