<?php
header("Content-Type:text/html;charset=utf-8");
/*字符串的统计与查找*/
//1.获取字符串的长度 //1)strlen函数:
//例:
/*$a="abcdef";
echo strlen($a);//输出:6;*/ //2)mb_strlen函数:
//例:
/*$a="美丽中国";
echo mb_strlen($a,'utf-8');//输出:4*/ //3)mb_internal_encoding();设置和获取内部字符编码
//例:
/*mb_internal_encoding("UTF-8");
echo mb_internal_encoding();//输出:UTF-8*/ //2.strspn——计算字符串中全部字符存在于字符集合中的第一段字符的长度:
/*原型:int strspn ( string $subject , string $mask [, int $start [, int $length ]] )
功能:返回 subject 中全部字符仅存在于 mask 中的第一组连续字符(子字符串)的长度。
*/
//例:
/*$a=strspn("147258369abcdef789","123456789");
echo $a;//输出:9*/ //3.substr_count计算子字符串出现的次数: //例:
/*$a=substr_count("Welcome to China","to");
echo $a;//输出:1*/ //例:
/*$a=substr_count("this is dog","is",2,5);
echo $a;//输出:2*/ //4.strpos——查找字符串首次出现的位置:
//例:
/*$a=strpos("美丽中国","中");
echo $a;//输出:6*/ //5.stripos——查找字符串首次出现的位置(不区分大小写) //6.strrpos——计算指定字符串在目标字符串最后一次出现的位置。
//例:
/*$a="abcdec";
var_dump(strrpos($a,'c',2));//输出:int 5*/ //7.strripos——计算指定字符串在目标字符串最后一次出现的位置(不区分大小写) //8.strrchr——查找指定字符在字符串中最后一次出现的位置。
//例:
/*$path="D:abcdef";
echo substr(strrchr($path,':'),1);//输出:abcdef */ //9.strstr——查找字符串首次出现。截取查找到的位置之后的字符:
//例:
/*$str="name@example.com";
$a=strstr($str,"@",true);
echo $a;//输出:name; $b=strstr($str,"@");
echo $b;//输出:@example.com ;*/ //10.stristr——查找字符串首次出现(忽略大小写);
?>

PHP:第五章——字符串的统计及查找的更多相关文章

  1. PHP:第五章——字符串与数组及其他函数

    <?php header("Content-Type:text/html;charset=utf-8"); //1.str_split——将字符串转换为数组. /*$str= ...

  2. PHP:第五章——字符串转换与比较

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串的转换与比较 //1.ord——返回首字符的ASCLL: ...

  3. PHP:第五章——字符串加密及校验函数

    <?php header("Content-Type:text/html;charset=utf-8"); //1.md5——计算字符中的散列值 //对一段信息(Messag ...

  4. PHP:第五章——字符串过滤函数

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串过滤函数: //1.n12br 在所有新行之前插入Htm ...

  5. PHP:第五章——字符串输出函数

    <?php header("Content-Type:text/html;charset=utf-8"); /*字符串输出函数*/ //1.echo 输出一个或多个字符 // ...

  6. PHP:第五章——字符串的分割与替换

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串的截取与分割 //1.字符串截取类函数 //1)trim ...

  7. PHP:第五章——字符串的概念

    <?php header("Content-Type:text/html;charset=utf-8"); //字符串概念: //1.单引号.//里面的变量不会被解释 //例 ...

  8. PHP:第五章——字符串编码函数

    <?php header("Content-Type:text/html;charset=utf-8"); //1.base64_encode和base64_decode.6 ...

  9. 《程序员代码面试指南》第五章 字符串问题 去掉字符串中连续出现k 个0 的子串

    题目 去掉字符串中连续出现k 个0 的子串 java代码 package com.lizhouwei.chapter5; /** * @Description: 去掉字符串中连续出现k 个0 的子串 ...

随机推荐

  1. 利用burpsuite实现重放攻击

    1.什么是重放攻击? 顾名思义,重复的会话请求就是重放攻击.可能是因为用户重复发起请求,也可能是因为请求被攻击者获取,然后重新发给服务器. 附上详细的解释:http://blog.csdn.net/k ...

  2. 模拟百度云盘版的ftp

    思路:一.分两个大的文件夹,一个是客户端,一个服务端的 二.实现的功能 1.    登陆--对用户名的合法性进行检测(实验账户:alex,123)                注册--设置账户,其中 ...

  3. Shell特殊变量介绍与实践 $0

    2.$0特殊变量的作用及变量实践$0的作用为取出执行脚本的名称(包括路径) ,下面是该功能的实践.范例4-4:获取脚本的名称及路径. [root@salt-client- sh1]# cat n1.s ...

  4. python实现文件夹遍历

    python 中os.path模块用于操作文件或文件夹 os.path.exists(path) 判断文件路径是否存在 dir = "c:\windows"if os.path.e ...

  5. 1.2 Getting Started--Naming Conventions(命名约定)

    Ember.js使用一个运行时解析器去连接你的对象而没有很多样板文件.作为一个开发者,如果你把code放到约定好的位置这个解析器会自动工作.   一.The Application     1. 当你 ...

  6. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

  7. UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 51: ord

    1.问题描述:一个在Django框架下使用Python编写的定时更新项目,在Windows系统下测试无误,在Linux系统下测试,报如下错误: ascii codec can't decode byt ...

  8. Flume环境安装

    源码包下载: http://archive.apache.org/dist/flume/1.8.0/ 集群环境: master 192.168.1.99 slave1 192.168.1.100 sl ...

  9. Django加载静态网页模板

    Django加载静态网页模板 步骤: 第一步:在子系统blog根目录下新建模版目录templates,里面新建一个login.html <!DOCTYPE html> <html l ...

  10. 20155201 2016-2017-2 《Java程序设计》第四周学习总结

    20155201 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 - 第六章要点: 继承:面向对象中,子类继承父类,避免重复的行为定义.继承基本上就是避免多个 ...