0
嗨,我想找到如果字符串内容这个“|”这个角色。preg_match只找到这个特殊字符“|”在字符串
例如: -
$string = '$18,000 | new price';
if (preg_match('/[^|]/', $string)) {
}
else {
}
嗨,我想找到如果字符串内容这个“|”这个角色。preg_match只找到这个特殊字符“|”在字符串
例如: -
$string = '$18,000 | new price';
if (preg_match('/[^|]/', $string)) {
}
else {
}
这应该做的工作。
$string = '$18,000 | new price';
if (strpos($string , '|') === false) {
// Not found.
}
else {
// Found.
}
图案是错误的。在这种情况下不需要^
。应该是 -
preg_match('/[|]/', $string);
您可以使用storpos
-
$string = '$18,000 | new price';
if(strpos($string, '|')) { ... }
http://php.net/strpos –
真棒感谢我认为这将解决问题。 –
不客气。我也用'strpos'发布了代码。 –