Php regular expression extract Image address hyperlink title implementation code

Source: Internet
Author: User
Tags php regular expression
This article introduces how to use php regular expressions to extract the title of an image URL hyperlink. For more information, see. The regular expression extracts the id code from the URL as follows to copy the code pre...

This article introduces how to use php regular expressions to extract the title of an image URL hyperlink. For more information, see.

The regular expression extracts the id from the URL

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


PHP regular expression to extract the image address code.

The code is as follows:
$ Str ='

'; $ Pattern = "/<[img | IMG]. *? Src = ['| "] (. *? (? : 2.16.gif |. jpg]) ['| "]. *? [/]?> /"; Preg_match_all ($ pattern, $ str, $ match); print_r ($ match );

PHP regular expression to extract hyperlinks and their titles

Using regular expressions is the simplest. other methods, even if you want to use regular expressions, are used...

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

Output method:

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

';
The code is as follows:

$ Str = 'Song list
Chinese score list

• Light Music



Address:

Reprinted at will, but please attach the article address :-)

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.