Okay, let me ask a few questions without using regular expressions and see how I solve them.
1. Clear all tags in HTML, leaving only hyperlinks.
I use strip_tags.
Strip_tags ($ data, $ tags)
$ Data is a string, $ tags is a tag that retains.
strip_tags($data,'’) is enough. Finished? Yes, it's that simple.
If I still want to keep , then strip_tags($data,'')
2. Intercept the characters from $str1 to $str2 in $str The first match of the string.
function str_cut($str,$start, $end) {//Get the first match, the most efficient
$content = strstr($str, $start);
$content = substr( $content, strlen( $start ), strpos( $content, $end ) - strlen( $start ) );
return $content;
}
3. Intercept $str All matches of the string from $str1 to $str2.
function my_Ca($content,$start,$end){//Get 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 $a;
}
Summary: As long as you think more and summarize more, without using regular rules, you can solve most problems using the functions that come with PHP.