php strchr()函数
php strchr()函数是用来查找字符串中第一次出现的字符位置,并返回该字符及其后面的所有字符。
该函数的语法格式如下:
string strchr ( string $haystack , mixed $needle [, bool $part = false ] )
其中,参数haystack是查找的字符串;needle是要查找的字符;part参数用于指定是否只返回needle之前的字符串,默认为false,即返回needle及其后面的所有字符。
下面是一个使用strchr()函数的示例:
$str = 'This is a test string'; echo strchr($str, 'i'); //输出 is a test string echo strchr($str, 'i', true); //输出 Th
上面的代码中,我们使用strchr()函数查找字符串中第一次出现的字符“i”,并返回该字符及其后面的所有字符,即“is a test string”;如果将part参数设置为true,则只返回needle之前的字符串,即“Th”。