Please php regular expression walk away _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression
Ask php regular expression to go away. Okay, so I have a few questions and don't need regular expressions. let's see how I solve them. 1. clear all tags in HTML and only keep the hyperlink. I use strip_tags. Strip_tags ($ data, $ tags) $ data is good, so I have a few questions and don't need regular expressions. how can I solve them.

1. clear all tags in HTML and only keep the hyperlink.
I use strip_tags.
Strip_tags ($ data, $ tags)
$ Data is a string and $ tags is a reserved tag.
Strip_tags ($ data. Finished? Yes, that's simple.
If I want to keep it, strip_tags ($ data ,'')

2. intercept the first match between $ str1 and $ str2 in $ str.

Function str_cut ($ str, $ start, $ end) {// retrieve the first match with the highest efficiency
$ Content = strstr ($ str, $ start );
$ Content = substr ($ content, strlen ($ start), strpos ($ content, $ end)-strlen ($ start ));
Return $ content;
}

3. intercept all matching strings from $ str1 to $ str2 in $ str.

Function my_Ca ($ content, $ start, $ end) {// retrieve all matches, excluding the start and end strings
$ M = explode ($ start, $ content );
$ A = array ();
$ Sum = count ($ m );
For ($ I = 1; $ I <$ sum; $ I ++)
{
$ My = explode ($ end, $ m [$ I]);
$ A [] = $ my [0];
Unset ($ my );
}
Return $;
}

Conclusion: you only need to think more about it and do not need regular expressions. you can solve most of the problems with the built-in functions of PHP.

Bytes. 1. clear all tags in HTML and only keep the hyperlink. I use strip_tags. Strip_tags ($ data, $ tags) $ data is...

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.