到目前爲止:我正在做一個preg_match_all搜索和我的輸出:唐納德,雛菊,休伊,杜威和路易
代碼是這樣的:
$duckburg = array();
preg_match_all($pattern,$subject,$match);
$duckburg['residents'] = $match[1];
print_r($duckburg['residents']);
輸出:
Array ([residents] => Array ([0] => Donald [1] => Daisy [2] => Huey [3] => Dewey [4] => Louie)
我的問題:我想補充到每個字符串「鴨子」
使用此幫助-ST環:$lastname = " Duck"
輸出應該是:
Array ([residents] => Array ([0] => Donald Duck [1] => Daisy Duck [2] => Huey Duck [3] => Dewey Duck [4] => Louie Duck)
我試圖(但它不工作):
preg_match_all($pattern,$subject,$match);
$matchy = $match.$lastname;
$duckburg['residents'] = $matchy[1];
print_r($duckburg['residents']);
是否有可能改變匹配字符串它進入前陣?感謝您的幫助!
使用'$ duckburg [ '居民'] = $ matchy;''不是'$ duckburg ['居民'] = $ matchy [1]; ' –