Php regular expression extract Image address hyperlink title implementation code _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression
Php regular expression extracts the title of the image address hyperlink. This article introduces how to use php regular expressions to extract the title of an image URL hyperlink. For more information, see. The following is a copy of the id code in the regular expression extraction URL. This article describes how to extract the title of an image address hyperlink using the php regular expression. 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

Refer to the hyperlink title implementation code. For more information, see. The id code in the regular expression extraction URL is copied 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.