简单的 PHP 正则表达式字符串以开头


Simple PHP Regex String Starts With

如果一个字符串以另一个字符串开头,我正在寻找要引导的正则表达式。这必须是正则表达式,它必须是PHP正则表达式。

$result = preg_match("#^startText(.*)$#i", $string);
if($result == 0)
{
    echo "No match";
}
else
{
    echo "Match found.";
}

PHP.net 正则表达式

preg_match返回0未找到匹配项,或返回1,因为preg_match在第一个匹配项停止。如果要计算所有匹配项,请使用 preg_match_all

如果您遇到更多麻烦,请查看 PHP 网站。