开发者

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

开发者 https://www.devze.com 2023-02-11 06:57 出处:网络
How do you match the character ^ at th开发者_StackOverflow社区e beginning of the string?i think the simple

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

精彩评论

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

关注公众号