Questions about PHP information retrieval

Source: Internet
Author: User
Tags ereg
Questions about PHP Information Retrieval & lt ;? Php & nbsp; $ baidu = "http://www.baidu.com/s? Wd = site % 3Ahao123.com "; & nbsp; $ site = file_get_contents ($ baidu); & nbsp; & Questions About PHP information retrieval
 $ Baidu = "http://www.baidu.com/s? Wd = site % 3Ahao123.com ";
$ Site = file_get_contents ($ baidu );
$ Site = iconv ("UTF-8", "GB2312", $ site );
Ereg ("(.*)", $ Site, $ count );
Print_r ($ count); // Obtain the number of topics indexed in Baidu

?>

Result: Array ([0] => [1] => Baidu search _ site: hao123.com)
However:
 $ Baidu = "http://www.baidu.com/s? Wd = site % 3Ahao123.com ";
$ Site = file_get_contents ($ baidu );
$ Site = iconv ("UTF-8", "GB2312", $ site );
Ereg ("(.*)", $ Site, $ count );
Print_r ($ count); // Obtain the number of topics indexed in Baidu

?>

This won't work...
Please explain how to get Baidu's indexing ....
------ Best solution --------------------

Preg_match ('%Find the number of related results (.*?) .% I ', $ site, $ count );

------ Other solutions --------------------

The "." in the regular expression matches any character except "\ n" and cannot match Chinese characters.
Preg_match ('%Find the number of related results (.*?) .% I ', $ site, $ count );
Same as the following:
Preg_match ('/Find the number of related results (.*?) ./I ', $ site, $ count );

------ Other solutions --------------------
Reference:
PHP code? 12preg_match ('% Find the number of related results (.*?) .% I ', $ site, $ count );

In fact
Preg_match ('/Find the number of related results. <\/Strong>/I ', $ site, $ count );

You can.
------ Other solutions --------------------
%Find the number of related results (.*?) .The key to % I is that the last "I" indicates that case sensitivity is ignored. if "I" is not added, "%" is not required.
------ Other solutions --------------------
Reference:
Reference: % is only the start and end character of the regular expression. you can use/, # to start and end the regular expression. it is not ^ $ the first time I heard about it, I was taught ......

What you are talking about is Location Matching. what you are talking about is not one thing.
------ Other solutions --------------------
% Is only the start and end of the regular expression. you can use /, #.
------ Other solutions --------------------
Reference:
% Is only the start and end of the regular expression. you can use /, #.
The start and end of the regular expression are not ^ $ the first time I heard about it, I was taught ......
------ Other solutions --------------------
After learning, I can't quite understand it ..
------ Other solutions --------------------
The above error is reported. "." can match Chinese characters.
------ Other solutions --------------------
This problem mainly applies regular expressions.
------ Other solutions --------------------
Can you tell me why I want to add %?
------ Other solutions --------------------
The reply was deleted by the administrator at 17:27:11, January 19 ,.

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.