PHP Regular expression extract picture address hyperlink title Implementation Code _php tutorial

Source: Internet
Author: User
Tags php regular expression
This article introduced the use of PHP regular expression to extract the image address hyperlink title Implementation code, there is a need for friends to refer to.

The regular expression extracts the id in the URL

The code is as follows Copy Code
Preg_match ('/http://t.sina.com.cn/(d+)/fans//', $html, $result); The regular expression extracts the id in the URL
echo $result [1];


PHP's regular expression extracts the code for the image address.

The code is as follows Copy Code
$str = '

'; $pattern = "/<[img| Img].*?src=[' | "] (.*? (?: [. gif|. JPG])) [' | ']. *? [/]?>/]; Preg_match_all ($pattern, $str, $match); Print_r ($match);

PHP Regular Expressions extract hyperlinks and their headings

Using regular expressions is the simplest, and the other way, even rice to think ...

$pat = '/(. *?) /I ';
Preg_match_all ($pat, $str, $m);

Output method:

Print_r ($m [2]);
Print_r ($m [4]);

';
The code is as follows Copy Code

$str = ' song list
Chinese Melody List

• Light Music

http://www.bkjia.com/PHPjc/631607.html www.bkjia.com true http://www.bkjia.com/PHPjc/631607.html techarticle This article introduced the use of PHP regular expression to extract the image address hyperlink title Implementation code, there is a need for friends to refer to. The ID code in the regular expression fetch URL is as follows ...

  • 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.