Matches the URL of the page content, how to resolve

Source: Internet
Author: User
Regular URLs that match the content of the Web page
I want to match the URL of this URL http://www.425sf.com/.
PHP Code
  
   $url = "http://www.425sf.com/";//capture Address $content = file_get_contents ($url); $patten = "^ ((https|http|ftp|rtsp|mms)?:/ /)? ([0-9a-z_!~* ' (). &=+$%-]+:)? [0-9a-z_!~* ' (). &=+$%-]+@)? ([0-9]{1,3}\.) {3} [0-9] {1,3}| ([0-9a-z_!~* ' ()-]+\.) * ([0-9a-z][0-9a-z-]{0,61})? [0-9a-z]\. [A-z] {2,6}) (: [0-9]{1,4})? ((/?)| (/[0-9a-z_!~* ' ().;?: @&=+$,%#-]+) +/?) $ ";p reg_match_all ($patten, $content, $matches);

The above matching regular I was referring to here
Http://topic.csdn.net/u/20070307/14/87e6b878-800e-4a88-830e-7d0eeeaba891.html
I tried to be more accurate with regular test tools.
But PHP doesn't seem to work here.

------Solution--------------------
PHP Code
$html = <<
  
   http://www.baidu.com [1] = http://hi.baidu.com?info=aaa) */
   
------Solution--------------------
LS Positive solution:


Preg_match_all
(PHP 4, PHP 5)

Preg_match_all― Global Regular expression matching

Description
int Preg_match_all (string $pattern, String $subject, array $matches [, int $flags])
Searches in subject for all content that matches the regular expression given by the pattern and places the result in matches in the order specified by flags.

After the first match is searched, the next search starts at the end of the previous match.

Flags can be a combination of the following tags (note that it makes no sense to combine Preg_pattern_order and Preg_set_order):

Preg_pattern_order
The results are sorted so that the $matches [0] is an array of all pattern matches, $matches [1] is an array of strings that match the sub-patterns in the first parenthesis, and so on.


Preg_match_all ("|<[^>]+> (. *) ]+>| U ",
" Example:This is a test ",
$out, Preg_pattern_order);
Print $out [0][0]. ",". $out [0][1]. " \ n ";
Print $out [1][0]. ",". $out [1][1]. " \ n ";
?>
This example will output:

Example:, this is a test
Example:, this is a test
Therefore, $out [0] contains a string that matches the entire pattern, $out [1] contains a string between a pair of HTML tags.


Preg_set_order
The result is sorted so that $matches [0] is an array of the first set of matches, $matches [1] is an array of the second set of matches, and so on.

Preg_match_all ("|<[^>]+> (. *) ]+>| U ",
" Example:This is a test ",
$out, Preg_set_order);
Print $out [0][0]. ",". $out [0][1]. " \ n ";
Print $out [1][0]. ",". $out [1][1]. " \ n ";
?>
This example will output:

Example:, Example:
This is a test that is a test

In this example, $matches [0] is the first set of matching results, $matches [0][0] contains text that matches the entire pattern, $matches [0][1] contains the text that matches the first sub-pattern, and so on. Similarly, $matches [1] is the second set of matching results, and so on.

Preg_offset_capture
If this tag is set, the matching result for each occurrence also returns its subordinate string offset. Note that this changes the value of the returned array so that each cell is also an array, where the first item is the matching string, and the second item is its offset in subject. This tag is available from PHP 4.3.0.


If no token is given, it is assumed to be preg_pattern_order.

Returns the number of times the entire pattern match (possibly 0), if an error returns FALSE.


Example #1 Get all the phone numbers from a text

Preg_match_all ("/\ (? (\d{3})? \)? (? (1) [\-\s]) \d{3}-\d{4}/x ",
"Call 555-1212 or 1-800-555-1212", $phones);
?>


Example #2 Search for matching HTML tags (greedy)

\\2 is an example of a reverse reference, and its meaning in PCRE is
Must match the contents of the second set of parentheses in the regular expression itself, in this case
Is ([\w]+). Because the strings are in double quotes, you need to
Add a backslash.
$html = " Bold textClick Me ";
  • 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.