如何在行結尾刪除NULL?從字符串末尾刪除NULL
懷俄明州MI NEW JERSEY 07728電腦維修TECHNULL
$phrases = array("NEW YORK NY", "NEW JERSEY", "SOUTH DAKOTA", "SOUTH CAROLINA", "COMPUTER REPAIR TECH","YORK NY","07728","WYOMING MI","WYOMING MINNESOTA");
$string = ("I live in wyoming Minnesota, but used to live in New Jersey 07728 working as a computer repair tech.");
$string = strtoupper($string);
$matches = stringSearch($phrases, $string);
var_dump($matches);
function stringSearch($phrases, $string){
$phrases1 = trim(implode('|', $phrases));
$phrases1 = str_replace(' ', '\s', $phrases1);
preg_match_all("/$phrases1/s", $string, $matches);
$value = implode(' ', array_filter($matches[0]));
echo $value;
}
非常感謝! – Lou
解決了您的問題? – Chris
是的,再次感謝。 – Lou