我正在将一个旧的 Perl 程序转换为 PHP,但与 Perl 相比,PHP 的字符串处理遇到了问题。
在 Perl 中,如果我想知道 $string
是否包含 this
、that
或 the_other
我可以使用:
if ($string =~ /this|that|the_other/){do something here}
PHP 中有等效的吗?
最佳答案
您可以使用正则表达式(例如 preg_match
):
if(preg_match('/this|that|the_other/', $string))
或使其明确(例如 strstr
):
if(strstr($string, 'this') || strstr($string, 'that') || strstr($string, 'the_other'))
关于php - PHP 相当于 Perl 的正则表达式替换是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3951016/