Javascript-php automatically generates a link to the url and then extracts the title

Source: Internet
Author: User
If the url is entered, the link can be automatically generated, and the title of the link will be crawled. Is there any good method? Use php or js. If the url is entered, the link can be automatically generated, and the title of the link will be crawled. Is there any good method?
Use php or js.

Reply content:

If the url is entered, the link can be automatically generated, and the title of the link will be crawled. Is there any good method?
Use php or js.

1. the URL entered by the user is submitted to PHP asynchronously after jQuery is used to check the URL validity.
2. PHP checks whether the URL is legal and uses Curl to obtain the URL content.
3. PHP returns the Title or error information to the front-end jQuery.


  False, CURLOPT_URL => $ url, // some websites are redirected to 301. CURLOPT_FOLLOWLOCATION => true, // The Connection timeout value is set to 5 seconds. CURLOPT_CONNECTTIMEOUT => 5, // The response timeout value is 5 seconds. CURLOPT_TIMEOUT => 5, CURLOPT_VERBOSE => false, CURLOPT_AUTOREFERER => true, // receives all the encoding CURLOPT_ENCODING => '', // returns the page content CURLOPT_RETURNTRANSFER => true,); $ response = curl_exec ($ ch ); // detect the webpage encoding, the non-UTF-8 encoding page, unified conversion for UTF-8 processing. if ('utf-8 '! = ($ Encoding = mb_detect_encoding ($ response, array ('utf-8', 'cp936 ', 'ascii') {$ response = mb_convert_encoding ($ response, 'utf-8', $ encoding);} // match the title $ title = 'title not obtained successfully '; if (preg_match ('#(.*)# IsU ', $ response, $ match) {$ title = $ match [1];} echo $ title;

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.