PHP字符串处理函数示例学习笔记
gt
html
lt
quot
template
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here 字符串的输出函数echo() $str = "Hello World"; echo $str; ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here程序报错后终止继续运行的函数die() $conn = @mysql_connect("localhost", "root", "root") or die("数据库连接失败!"); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here打印函数print_r() $arr = array('0'=>'PHP',"1"=>array('0'=>'P', '1'=>'H', '2'=>'P')); print_r($arr); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here字符串分割函数explode() $str = "PHP,JSP,JAVA,C++,HTML"; print_r(explode(",",$str)); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here数组元素组合成字符串的函数implode() $arr = array('Hello', 'World!', 'Beautiful', 'Day!'); echo implode(" ", $arr); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here预定义字符串转换为HTML实体的函数htmlspecialchars() $str = "<strong>PHP100.COM"; echo htmlspecialchars($str); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here $str = "<font color='red'>PHP + <em>Apache</em> + <b>Mysql</b>"; echo strip_tags($str); echo "<br>"; echo strip_tags($str, "<font>"); echo "<br>"; echo strip_tags($str, "<font><em><b>"); ?> </b></em></font></font>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here去除字符串首尾连续空格的函数 $str = " PHP100 "; echo strlen($str)."<br>"; echo strlen(ltrim($str))."<br>"; echo strlen(rtrim($str))."<br>"; echo strlen(trim($str)); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here echo nl2br("PHP100.COM \n PHP100.NET"); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here加密函数MD5 $str = "PHP100.COM"; echo md5($str); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here加密函数sha1() $str = "PHP100.COM"; echo sha1($str); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here字符串替换函数str_replace() $str = "baidu.com"; echo str_replace("baidu", "php100", $str); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here数字分组格式化函数number_format() $number = "1234567890"; echo number_format($number); echo "<br/>"; echo number_format($number,2); echo "<br>"; echo number_format($number,2,",","."); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here字符串分割函数str_split() $str = "Hello World"; $arr1 = str_split($str); $arr2 = str_split($str,3); print_r($arr1); print_r($arr2); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here字符串截取函数substr() echo substr("WWW.PHP100.COM", 4); ?>
登录后复制
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <meta charset="UTF-8"> <title></title> <?php // put your code here $str = "我是一名PHP程序员"; echo iconv('UTF-8', 'GBK', $str); echo iconv_substr($str, "2", "2", "UTF-8"); ?>
登录后复制
以上就介绍了PHP字符串处理函数示例学习笔记,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
2 周前
By DDD
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
1 个月前
By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)
