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
}
精彩评论