《PHP實戰:php實現指定字符串中查找子字符串的方法》要點:
本文介紹了PHP實戰:php實現指定字符串中查找子字符串的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了php實現指定字符串中查找子字符串的辦法.分享給大家供大家參考.具體分析如下:
PHP編程對strpos()函數可以用來在php中查找子字符串.strpos()函數將試圖找到子字符串在源字符串中首次出現的位置.如果找到了,它會返回一個非負整數表示子字符串出現的位置. 否則它會返回一個布爾值false.
PHP編程
<?php
$haystack1 = "2349534134345w3mentor16504381640386488129";
$haystack2 = "w3mentor234953413434516504381640386488129";
$haystack3 = "center234953413434516504381640386488129fyi";
$pos1 = strpos($haystack1, "w3mentor");
$pos2 = strpos($haystack2, "w3mentor");
$pos3 = strpos($haystack3, "w3mentor");
print("pos1 = ($pos1); type is " . gettype($pos1) . "\n");
print("pos2 = ($pos2); type is " . gettype($pos2) . "\n");
print("pos3 = ($pos3); type is " . gettype($pos3) . "\n");
?>
PHP編程輸出結果:
PHP編程
pos1 = (13); type is integer
pos2 = (0); type is integer
pos3 = (); type is boolean
PHP編程pos3返回的是bool值,即沒有找到子字符串
PHP編程希望本文所述對大家的php程序設計有所贊助.
歡迎參與《PHP實戰:php實現指定字符串中查找子字符串的方法》討論,分享您的想法,維易PHP學院為您提供專業教程。