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;