在字符串的第一个位置找到 preg_match 的“/p”

find "/p" with preg_match in first place of string

小问题:

$content='/p test some text';

当“/p”在该行的前面时,字符串应该分解为一个数组

if(preg_match('^(/p)',$content)==true) {
$private=explode(" ",$content,3);
}

我认为他们是一个错误,但我不知道正确的搜索参数

这应该适合你:

(不需要将它与 true 进行比较,因为如果它没有找到任何东西它 returns 一个空数组,那么它就是 false。你还需要 delimiters 作为你的正则表达式和转义带反斜杠的斜杠)

$content='/p test some text';
if(preg_match('/^\/p/',$content)) {
             //^    ^ See delimiters
    $private=explode(" ",$content,3);
}

为什么不做个简单的测试

if ($content{0} == '/' && $content{1} == 'p' ) { 
    $private=explode(" ",$content,3); 
}