Blogger Information
Blog 4
fans 0
comment 0
visits 2233
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP对字符串的处理规则 4月11日作业
人生的博客
Original
549 people have browsed it

PHP对字符串的处理是一个很常见的作业,有很多细节上的不同

代码:

实例

<meta charset="UTF-8">
<?php
//输出语句:echo与print
echo '<hr>';
print 113;
echo '<br>';
echo 5;
echo '<br>';
echo 'abcd';
echo '<hr>';


$m = '100元';
$y1 = '小明{$m}买了个篮球';
$y2 = "小明{$m}买了个篮球";
$y3='小明"{$m}"买了个篮球';
echo $y1;     //小明{$m}买了个篮球
echo '<br>';
echo $y2;     //小明100元买了个篮球
echo '<br>';
echo $y3;     //小明"{$m}"买了个篮球
echo '<br>';
echo "小明{\$m}买了个篮球";
echo '<hr>'; 

echo nl2br("day.\nmouth."); //day.
echo '<br>';         //mouth.
echo nl2br('day.\nmouth.');        //day.\nmouth.
echo '<br>';
echo 'day.\nmouth.';        //day.\nmouth.
echo '<br>';
echo "day.\nmouth.";  
echo '<br>';
echo "day.\\nmouth.";  
echo '<br>';
echo nl2br("day.<br>mouth.");

?>

运行实例 »

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

在对字符处理时,有很多注意事项:

  1. 双引号包装的字符串可以用 {} 解析内部的变量名,单引号原样输出;

  2. 使用转义字符:反斜线,将原字符进行转义,使其失去原有的作用

    转义字符在单引号包装与双引号包装使用效果不同。

Correction status:Uncorrected

Teacher's comments:
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