Blogger Information
Blog 57
fans 0
comment 0
visits 47013
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
三个常用的字符串查询函数
藍錄的博客
Original
688 people have browsed it

实例

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

// substr(), 索引从11开始的剩余内容,根据位置查询
echo substr($str, 11), '<br>';
echo substr($str, 11,4), '<br>'; // 区间查询,11开始取4个
echo substr($str, -3), '<br>'; // 区间查询,11开始取4个

//strstr($str1, $str2,bool)
$email = 'admin@php.cn';
// 查询@是否存在,默认返回@以及后面的内容
echo strstr($email, '@'),'<br>';
// 传入第三个参数:true,仅返回@符之前的内容(不包含@)
echo strstr($email, '@',true),'<br>';
echo strstr($email, '@',true),strstr($email, '@'),'<br>';


// strpos($str1, $str2, $start): 根据内容查询,返回字符串首次出现的位置
echo strpos($str, 'best');

运行实例 »

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

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