PHP正則表達(dá)式preg_match輸出問題
<?php
//$pattern=正則表達(dá)式
//$subject=匹配的目標(biāo)數(shù)據(jù)
//preg_match,preg_match_all
$pattern='/[0-9]/';
$subject='we56sd8g7f54gf23121xcv234gjyt8';
$m1=$m2=array();
preg_match($pattern,$subject,$m1);
preg_match_all($pattern,$subject,$m2);
show($m1);
echo '<hr>';
show($m2);
function show ($val =null){
?? ?if(empty($var)){
?? ??? ?echo 'null';
?? ?}else if(is_array($var)||is_object($var)){
?? ??? ?//array object
?? ??? ?echo '<pre>';
?? ??? ?print_($var);
?? ??? ?echo '<pre>';
?? ?}else{
?? ??? ?//string int float...
?? ??? ?echo $var;
?? ?}
}
代碼如上所示。。輸出的結(jié)果為兩個(gè)null,請(qǐng)問各位大神我的代碼哪里錯(cuò)了?謝謝
(返回的代碼應(yīng)該是匹配到的兩個(gè)只包含數(shù)字的數(shù)組)
2018-11-24
show()這個(gè)函數(shù)傳遞的參數(shù)敲錯(cuò)了,function show ($val =null){,應(yīng)該是$var ,你敲成$val
2016-11-10
數(shù)組參數(shù)寫成值傳遞了,改成引用傳遞:
preg_match($pattern,$subject,&$m1)