Please go away with php regular_PHP tutorial

WBOY
Release: 2016-07-21 15:53:42
Original
779 people have browsed it

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.

http://www.bkjia.com/PHPjc/318680.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318680.htmlTechArticleOkay, 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template