开发者

How do you match the character ^ at the beginning of the string?

How do you match the character ^ at th开发者_StackOverflow社区e beginning of the string?


i think the simple

if($string[0]=='^')

In PHP a string is actually an array, so $foo ="string", you could access the "s" with $foo[0], the "t" with $foo[1], and so on ..


To check if strings starts with a ^

if(strpos($subject, "^") === 0){

}

or

if (preg_match('/^\^/', $subject)) {
    # Successful match
} else {
    # Match attempt failed
}


If I understood you correctly, thats what you need:

if(strcmp('^', substr($yourString, 0, 1)) === 0) { 
    //Do your thing
} else {
    // Dont
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜