为了账号安全,请及时绑定邮箱和手机立即绑定

分享一下老师讲课的代码,我把所有函数的放一起了

<?php

$pattern = '/[0-9]/';
$subject = 'wodedi1an3hsh4i12345ujhuj5hh68j';
$replacement = '幕女神';

$pattern1 = array('/[0123]/','/[456]/','/[789]/');
$subject1 = 'wodedi1an3hsh4i12345ujhuj5hh68j';
$replacement1 = array('幕','女','神');

$pattern2 = array('/[0123]/','/[456]/','/[789]/');
$subject2 = array('wode','di1a','n3hsh4','i12345','ujhuj5h','h68j');
$replacement2 = array('幕','女','神');

$pattern3 = '/[0-9]/';
$subject3 = array('wode','di1a','n3hsh4','i12345','ujhuj5h','h68j');

$pattern4 = '/[0-9]/';
$subject4 = '慕1女2神3约吗5?';

$str9 = '你好{慕女神}[约吗]?';

echo "preg_replace and preg_filter测试</br>";
$str1 = preg_replace($pattern, $replacement, $subject);
$str2 = preg_filter($pattern, $replacement, $subject);
$str3 = preg_replace($pattern1, $replacement1, $subject1);
$str4 = preg_filter($pattern1, $replacement1, $subject1);
$str5 = preg_replace($pattern2, $replacement2, $subject2);
$str6 = preg_filter($pattern2, $replacement2, $subject2);
$str7 = preg_grep($pattern, $subject3);
$str8 = preg_split($pattern4, $subject4);
$str9 = preg_quote($str9);

show($str1);
echo '<hr />';
show($str2);
echo '<hr />';
show($str3);
echo '<hr />';
show($str4);
echo '<hr />';
show($str5);
echo '<hr />';
show($str6);
echo "preg_replace and preg_filter测试end</br><hr />";

echo 'preg_grep测试';
show($str7);
echo "preg_grep测试end</br><hr />";

echo 'preg_split测试';
show($str8);
echo "preg_split测试end</br><hr />";

echo 'preg_quote测试';
show($str9);
echo "preg_quote测试end</br><hr />";

function show($var = null){
    if(empty($var)){
        echo 'null';
    }elseif (is_array($var) || is_object($var)){
        echo '<pre>';
        print_r($var);
        echo '<pre>';
    }else {
        echo $var;
    }
}

?>

正在回答

1 回答

懒人的福音

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

分享一下老师讲课的代码,我把所有函数的放一起了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信