PHP 字符串 strrchr() 函數(shù)
strrchr() 函數(shù)是 PHP 的內(nèi)建函數(shù)。愛掏網(wǎng) - it200.com它用于查找字符串的最后一次出現(xiàn)的位置。愛掏網(wǎng) - it200.com
此函數(shù)返回從該位置到字符串結(jié)尾的所有字符,如果未找到字符,則返回 FALSE。愛掏網(wǎng) - it200.com
注意:strrchr() 函數(shù)是二進(jìn)制安全的。愛掏網(wǎng) - it200.com
strrchr(string,char);
參數(shù) | 描述 | 必需/可選 |
---|---|---|
string | 指定要搜索的字符串。愛掏網(wǎng) - it200.com | 必需 |
char | 通過ASCII值指定要查找的字符串。愛掏網(wǎng) - it200.com | 必需 |
示例1
<?php
str1="Hello PHP";str2="PHP";
echo "Your first string is:".str1;
echo "<br>";
echo "Your second string is:".str2;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr(str1,str2);
?>
輸出:
Your first string is:Hello PHP
Your second string is:PHP
By using 'strrchr()' function:P
示例2
<?php
str="We are Learning PHP";
echo "Your string is:".str;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr("$str",are);
?>
輸出:
Your string is:We are Learning PHP
By using 'strrchr()' function:arning PH
示例3
<?php
str="Hello PHP";
echo "Your string is:".str;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr("$str",101);
// Search a string for the ASCII value of "e" (101) and
//return all characters from this position to the end of the string:
?>
輸出結(jié)果:
Your string is:Hello PHP
By using 'strrchr()' function:ello PHP
參見
strncmp() :對字符串的前n個字符進(jìn)行比較(區(qū)分大小寫)
strpbrk() :在字符串中搜索一組字符中的任意字符
strpos() :返回一個字符串在另一個字符串中第一次出現(xiàn)的位置(區(qū)分大小寫)
參考:
http://php.net/manual/zh/function.strrchr.php
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。