Home > Backend Development > PHP Tutorial > php 变换 html特殊符号

php 变换 html特殊符号

WBOY
Release: 2016-06-13 13:11:20
Original
1055 people have browsed it

php 转换 html特殊符号
我写的函数

//转换某些特殊字符
function format_html($str){
$str = str_replace('“', '“',$str);
$str = str_replace('”', '”',$str);
$str = str_replace('·', '·',$str);
$str = str_replace('‘', '‘',$str);
$str = str_replace('’', '’',$str);
$str = str_replace('…', '…', $str);
$str = str_replace('—', '―', $str);
return $str;
}

但是这些符号实在是太多了。网上说的,大概255个。这么多,怎么可能转的完,有没有什么方法?

------解决方案--------------------
....亲不用这么转的 “ 这种符号当网页不识别html语言是就会这么显示 如果页面时full html的话 就是“

------解决方案--------------------

PHP code

htmlspecialchars :

$htm = "<div>ab c</div>";
echo htmlspecialchars($htm);
#源码
#<div>ab c</div>
#页面
#<div>ab c</div> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template