首页 后端开发 php教程 PHP字符串处理函数示例学习笔记

PHP字符串处理函数示例学习笔记

Aug 08, 2016 am 09:27 AM
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(&#39;0&#39;=>'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(&#39;Hello&#39;, &#39;World!&#39;, &#39;Beautiful&#39;, &#39;Day!&#39;);
        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=&#39;red&#39;>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(&#39;UTF-8&#39;, &#39;GBK&#39;, $str);
        echo iconv_substr($str, "2", "2", "UTF-8");
        ?>
    

登录后复制

以上就介绍了PHP字符串处理函数示例学习笔记,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

HTML 中的表格边框 HTML 中的表格边框 Sep 04, 2024 pm 04:49 PM

HTML 表格边框指南。在这里,我们以 HTML 中的表格边框为例,讨论定义表格边框的多种方法。

HTML 左边距 HTML 左边距 Sep 04, 2024 pm 04:48 PM

HTML 左边距指南。在这里,我们讨论 HTML margin-left 的简要概述及其示例及其代码实现。

HTML 中的嵌套表 HTML 中的嵌套表 Sep 04, 2024 pm 04:49 PM

这是 HTML 中嵌套表的指南。这里我们讨论如何在表中创建表以及相应的示例。

HTML 表格布局 HTML 表格布局 Sep 04, 2024 pm 04:54 PM

HTML 表格布局指南。在这里,我们详细讨论 HTML 表格布局的值以及示例和输出。

HTML 输入占位符 HTML 输入占位符 Sep 04, 2024 pm 04:54 PM

HTML 输入占位符指南。在这里,我们讨论 HTML 输入占位符的示例以及代码和输出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在这里我们还分别讨论了 HTML 有序列表和类型的介绍以及它们的示例

在 HTML 中移动文本 在 HTML 中移动文本 Sep 04, 2024 pm 04:45 PM

HTML 中的文本移动指南。在这里我们讨论一下marquee标签如何使用语法和实现示例。

HTML onclick 按钮 HTML onclick 按钮 Sep 04, 2024 pm 04:49 PM

HTML onclick 按钮指南。这里我们分别讨论它们的介绍、工作原理、示例以及各个事件中的onclick事件。

See all articles