Regular expression-how does php use regular expressions to obtain the content of a tag?

Source: Internet
Author: User
{Code ...} like the above tag, I want to get the content of 1 and 2 of a tag (I am content 1 and I am content 2), do not want 3 (not including me ), the only difference between them is that the class tag may have different class positions !!! ** How can I obtain the regular expression?

  <A class = "myclass" target = "_ blank" href = "http://www.taobao.com/"> I am content 1<A target = "_ blank" class = "myclass" href = "http://www.baidu.com/"> I am content 2<A class = "noclass" target = "_ blank" href = "http://www.foobar.com/"> does not contain me

Like the above tag, I want to get the content of 1 and 2 of a tag (I am content 1 and I am content 2), do not want 3 (not including me ), the only difference between them isclassDifferent labelsclassThe location may be different !!! **

How can I obtain it using regular expressions?

Reply content:

   <A class = "myclass" target = "_ blank" href = "http://www.taobao.com/"> I am content 1<A target = "_ blank" class = "myclass" href = "http://www.baidu.com/"> I am content 2<A class = "noclass" target = "_ blank" href = "http://www.foobar.com/"> does not contain me

Like the above tag, I want to get the content of 1 and 2 of a tag (I am content 1 and I am content 2), do not want 3 (not including me ), the only difference between them isclassDifferent labelsclassThe location may be different !!! **

How can I obtain it using regular expressions?

Thank you.

$ Str = '<a class = "myclass" target = "_ blank" href = "http://www.taobao.com/"> I'm content 1Content 2Does not include me(.*)Array ([0] => <a class = "myclass" target = "_ blank" href = "http://www.taobao.com/"> I am content 1 <a target = "_ blank" class = "myclass" href = "http://www.baidu.com/"> I'm content 2 Array ([0] => I'm content 1 [1] => I'm content 2 )) */

Thank you for your invitation.

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.