box_2017
2017-09-15 17:22
<?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;
}
}
?>
懒人的福音
鬼斧神工之正则表达式
47865 学习 · 113 问题
相似问题
回答 1