我想找到一个字符串的一部分,如果是真的我想要输出它找到的整个字符串.
以下是一个例子:
$Towns = "Eccleston,Aberdeen,Glasgow"; $Find = "Eccle"; if(strstr($Find,$Towns)){ echo outputWholeString($Find,$Towns); // Result: Eccleston. }
如果有人能够阐明如何做到这一点,并且记住它不会是静态值; $Towns和$Find变量将在我的实时脚本上动态分配.
使用explode()和strpos()作为
原文链接:https://www.f2er.com/php/130668.html$Towns = "Eccleston,Glasgow"; $data=explode(",",$Towns);// $Find = "Eccle"; foreach ($data as $town) if (strpos($town,$Find) !== false) { echo $town; }