PHP 字符类处理函数

2020-12-11  本文已影响0人  answer6

主要注意的是, 字符串和数组一样,第一位的位置都是 0

echo substr("Hello world",6);    // world
echo substr("Hello world", 6, 2);   // wo
echo substr("Hello world",-1)  //d
$email  = 'name@example.com';
$domain = strstr( $email, '@' );
echo $domain; // @example.com

$user = strstr($email, '@', true); // 从 PHP 5.3.0 起
echo $user; //  name
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
上一篇下一篇

猜你喜欢

热点阅读