php课程 6-23 mb_substr字符串截取怎么用

一、总结

一句话总结:

1、mb_substr字符串截取怎么用?

参数为:起始位置,个数

$str='我是小金,我是中国人!';
echo "<a href='javacript:' title='{$str}'>".mb_substr($str,0,4)."...</a>";

二、php课程 6-23 mb_substr字符串截取怎么用

9.多字节处理函数

mb_substr($str,0,7,"utf-8");

正则的使用场景:

1.检查手机格式

/^\d{11}$/

2.检查邮箱格式

/^\w+@\w+\.\w+$/

3.检查手机是否是以139开头

/^139\d{8}$/

4.复杂的字符串替换环境

/(\d+)\-(\d+)\+(\d+)/

三、代码

parse_str解析地址参数

 <?php
$query='id=10&name=user1&age=20';
parse_str($query,$arr); echo "<pre>";
print_r($arr);
echo "</pre>";
?>

mb_substr字符串截取

<?php
$str='我是小金,我是中国人!'; echo "<a href='javacript:' title='{$str}'>".mb_substr($str,0,4)."...</a>";
?>

检查手机格式是否正确

<?php
$str='1362361440'; if(preg_match('/^\d{11}$/',$str)){
echo '手机格式正确!';
}else{
echo '手机格式有误!';
}
?>

检查手机格式是否是以139开头

<?php
$str='13623614403'; if(preg_match('/^139\d{8}$/',$str)){
echo '手机格式正确!';
}else{
echo '手机格式有误!';
}
?>

检查QQ邮箱是否正确

<?php
$str='447096447@qq.com'; if(preg_match('/^\d{6,11}@qq.\w+$/',$str)){
echo 'QQ邮箱格式正确!';
}else{
echo 'QQ邮箱格式有误!';
}
?>

反向引用:复杂的字符串替换

<?php
$str='2016-06+28'; echo preg_replace('/(\d+)\-(\d+)\+(\d+)/','$1/$2=$3',$str);
?>
 
 
 
 
 
 
 

php课程 6-23 mb_substr字符串截取怎么用的更多相关文章

  1. 字符串截取mb_substr

    mb_substr("字符串","截取开始位置","截取个数","编码格式如UTF-8")

  2. thinkPHP内置字符串截取msubstr函数用法详解

    作者:陈达辉 字体:[增加 减小] 类型:转载 时间:2016-11-15 我要评论 这篇文章主要介绍了thinkPHP内置字符串截取函数用法,结合实例形式分析了thinkPHP内置的字符串截取函数功 ...

  3. PHP採集利器:依据開始字符串和结束字符串截取须要的採集内容数据

    PHP採集利器:依据開始字符串和结束字符串截取须要的採集内容数据 function strCutByStr(&$str, $findStart, $findEnd = false, $enco ...

  4. Thinkphp 3.2中字符串截取

    将此方法放到Thinkphp/Common/function.php里/* * 字符串截取函数 * 大白驴 * 2016-11-29 qq 675835721 * */function msubstr ...

  5. php实现中文字符串截取各种问题

    用php截取中文字符串会出现各种问题,做一简单汇总,文中的问题暂时还未解决,有大神解决了问题欢迎指教 <?php header('Content-Type:text/html;charset=u ...

  6. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...

  7. shell字符串操作之cut---实现字符串截取

    shell中(字符串截取) cut是以每一行为一个处理对象的,这种机制和sed是一样的.(关于sed的入门文章将在近期发布) 2 cut一般以什么为依据呢? 也就是说,我怎么告诉cut我想定位到的剪切 ...

  8. php 字符串截取,支持中文和其他编码

    function.php //使用方法 $content= mb_substr($content,0,25,'utf-8'); /** * 字符串截取,支持中文和其他编码 * @static * @a ...

  9. PHP实现中文字符串截取无乱码

    在我们学习PHP知识的过程中,PHP截取字符串应该是一个非常常见的字符串基础操作了,想必大家都比较熟悉这方面知识点. 但是有些新手朋友们可能遇到过,当截取中英文字符串时出现乱码的情况,其实这个也是非常 ...

随机推荐

  1. [Javascript] Different ways to create an new array/object based on existing array/object

    Array: 1. slice() const newAry = ary.slice() 2. concat const newAry = [].concat(ary) 3. spread oprea ...

  2. 【习题 6-2 UVA - 712】S-Trees

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] dfs模拟一下就好. 先预处理一个dfs. 搞出来x叶子节点它的值是什么 [代码] /* 1.Shoud it use long l ...

  3. 洛谷—— P1434 滑雪

    https://www.luogu.org/problem/show?pid=1434#sub 题目描述 Michael喜欢滑雪.这并不奇怪,因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜 ...

  4. [React] Theme your application with styled-components and "ThemeProvider"

    In this styled-components lesson, we set a "primary color" within a UI "theme" o ...

  5. UVA 488 - Triangle Wave 水~

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. StackExchange.Redis 官方文档(五) Keys, Values and Channels

    原文:StackExchange.Redis 官方文档(五) Keys, Values and Channels Keys, Values and Channels 在使用redis的过程中,要注意到 ...

  7. python整除

    1.'/'除号与c不同,单个'/'是浮点除,两个除号'//'才是整除

  8. Linux平台Makefile文件的编写基础篇

    目的:        基本掌握了 make 的用法,能在Linux系统上编程. 环境:        Linux系统,或者有一台Linux服务器,通过终端连接.一句话:有Linux编译环境. 准备: ...

  9. Centos 6 DNS Server 配置

    安装bind yum install -y bind bind-chroot bind-utis 如果是Centos 5 # yum -y install bind caching-nameserve ...

  10. Spring Boot Freemarker特别篇之contextPath【从零开始学Spring Boot】(转)

    需求缘起:有人在群里@我:请教群主大神一个问题,spring boot  + freemarker 怎么获取contextPath 头疼死我了,网上没一个靠谱的 .我就看看之前博客中的 [Spring ...