Blogger Information
Blog 20
fans 0
comment 0
visits 14898
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
substr(),strstr(),strpos()函数 2018.8.27
李逍遥
Original
732 people have browsed it

实例

<?php
//三个最基本的最常用的子串查询函数
$kong = '<br>';
//1.substr() 只知道要获取子串的位置,精确查询
$str = 'PHP is the best language in the world';

//substr() 索引从3开始的剩余内容
echo substr($str,3);
echo $kong;
echo substr($str,3,5);//区间查询,从3开始再数3个
echo $kong;
echo substr($str,-3);  //最后往前数3个

//2. strstr() 默认返回所查询@字符以及@字符以后的内容
echo '<hr>';
$email = 'admin@qq.com';
echo strstr($email,'@');
echo $kong;
//传入第三个参数 true ,仅返回所查询字符@之前的内容,不包括@
echo strstr($email,'@',true);

//3. strpos() 根据内容查询,返回字符串出现的位置
echo strpos($str,'in');

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post