substr和strpos函数应用

PHP substr() 函数
语法

substr(string,start,length)

定义和用法
substr() 函数返回字符串的一部分。

注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。

<?php
echo substr("Hello world",6); world
echo substr("Hello world",0,10); Hello worl 
echo substr("Hello world",1,8); ello wor 
echo substr("Hello world",0,5); Hello 
echo substr("Hello world",6,6); world 
echo substr("Hello world",0,-1); Hello worl 
echo substr("Hello world",-10,-2); ello wor 
echo substr("Hello world",0,-6); Hello 
echo substr("Hello world",-2-3); world 
?>


 

PHP strpos() 函数
定义和用法
查找 "php" 在字符串中第一次出现的位置:


<?php
echo strpos("You love php, I love php too!","Y");     0

echo strpos("You love php, I love php too!","abc");   false 
?>