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 a string and $ tags is a reserved tag.
Strip_tags ($ data, '<A>. Finished? Yes, that's simple.
If I want to retain , strip_tags ($ data, '<A> ')
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.