htmlentities 函数结构与htmlspecialchars 函数类似
来源:互联网 发布:打字拼音软件下载 编辑:程序博客网 时间:2024/05/18 00:43
htmlentities 函数结构与htmlspecialchars 函数类似,下面通过实例来学习。
实例 3-9 htmlentities 函数的应用
本实例演示通过htmlentities 函数将所有文本实体转换成HTML 实体,如代码3-9 所示。
【代码 3-9】 htmlentities.php
<?php
$str = "A 'quote' is <b>bold</b>";
// 输出: A 'quote' is <b>bold</b>
echo htmlentities($str);
// 输出: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
通过浏览器的输出结果,可以发现两句话的显示效果一样
A 'quote' is <b>bold</b>
A 'quote' is <b>bold</b>
,但是查看源代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> htmlentities.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
A 'quote' is <b>bold</b><hr>A 'quote' is <b>bold</b>
</body>
</html>
,会发现是
不一样的,其中第1 句,单引号没有被转成文本实体,而第2 句被转了,如下所示:
A 'quote' is <b>bold</b>
A 'quote' is <b>bold</b>
(3)strip_tags()函数。strip_tags 函数将传入的字符串参数中的所有的PHP 和HTML 标记
去掉。函数声明如下:
string strip_tags ( string str [, string allowable_tags])
如果想保留某些特定的PHP 或者HTML 标记,可以在第二个参数allowable_tags 中
指定。
实例 3-10 去掉所有的HTML 和PHP 标记
本实例演示如何使用strip_tags 函数去掉所有的HTML 和PHP 标记,如代码3-10 所示。
【代码 3-10】 strip_tags.php
<?php
$text = '
<p>Test paragraph.</p>
<!-- Comment -->
Other text';
echo strip_tags($text);
echo "<BR>-------<BR>";
// 允许 <p>保留
echo strip_tags($text, '<p>');
?>
输出结果如图3-6 所示。
Test paragraph. Other text
-------
Test paragraph.
Other text
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> strip_tags.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
Test paragraph.
Other text<BR>-------<BR>
<p>Test paragraph.</p>
Other text </body>
</html>
- htmlentities 函数结构与htmlspecialchars 函数类似
- PHP中 htmlspecialchars,htmlentities, nl2br函数
- php函数之htmlspecialchars(),htmlentities()等
- PHP中 htmlspecialchars,htmlentities, nl2br函数
- PHP中htmlentities和htmlspecialchars函数的区别
- PHP中htmlentities()和htmlspecialchars()这两个函数的区别
- PHP函数—htmlentities 、htmlspecialchars、addslashes的使用
- 函数htmlspecialchars
- htmlentities() 函数用法
- htmlspecialchars htmlentities - stripslashes - addslahes
- htmlentities() 和 htmlspecialchars()区别
- htmlentities,html_entity_decode,htmlspecialchars_decode,htmlspecialchars
- htmlentities()和htmlspecialchars()概要
- 对字符串进行HTML转义:htmlspecialchars与htmlentities
- php中的htmlspecialchars函数
- PHP htmlspecialchars() 函数
- PHP htmlspecialchars() 函数
- php htmlspecialchars()函数
- Android应用优化_0.1版本
- Leetcode - Longest Increasing Subsequence
- 第十四章 老板回来了,我不知道—观察者模式
- javascript进阶(二)— — 小技巧合集
- ZOJ2110Tempter of the Bone(DFS模板题,迷宫问题)
- htmlentities 函数结构与htmlspecialchars 函数类似
- 登山-C#-DataGridView显示行号
- 导航栏上面添加UISearchBar pop回去的时候会把添加的导航栏带回去的问题
- HDU 1491 Octorber 21st (日期计算)
- 优先队列+括号配对 51Nod1476 括号序列的最小代价
- Storm处理流程, 基本参数配置
- Andrioid项目之九图灵机器人
- 线程间通信:生产者消费者(都要加锁,且为同一把锁)
- HTML5 audio标签使用 preload属性 规定是否在页面加载后载入音频