Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果一个字符串以另一个字符串开头,我正在寻找正则表达式。这必须是正则表达式,并且必须是 PHP 正则表达式。
$result = preg_match("#^startText(.*)$#i", $string); if($result == 0) { echo "No match"; } else { echo "Match found."; }
PHP.net 正则表达式
preg_match0未找到匹配项或1, 因为preg_match在第一个匹配项处停止而返回。如果要计算所有匹配项,请使用preg_match_all.
preg_match
0
1
preg_match_all
如果您遇到更多问题,请查看 PHP 网站。