上一篇文章中我们了解了对字符串进行编码和解码的方法,有需要的请看《php字符串函数运用之对字符串进行编码和解码》。这次我们向大家介绍HTML实体转换为字符的方法,有需要的可以参考参考。
首先我们来看一下什么叫做HTML实体。
有些字符,像(
了解什么叫html实体之后,我们就来介绍如何将html实体转换为字符。其实将hrml实体转换成字符的方法有两种,我们先来介绍第一种。
第一种、html_entity_decode() 函数
让我们来看一个小例子。
<?php $str = "<© 3WCSçh°°¦§>"; echo html_entity_decode($str); ?>
上面代码的 HTML 输出如下:
<!DOCTYPE html> <html> <body> <© 3WCSçh°°¦§> </body> </html>
上面代码的浏览器输出如下:
我们可以看这个小案例,它使用了html_entity_decode函数将html实体转换成字符。我们下面就来仔细看看。
先来看看这个函数的语法。
html_entity_decode(string,flags,character-set)
这第一个方法介绍完了,下面我们就来介绍第二种方法。
第二种、htmlspecialchars_decode()函数
我们来看一下栗子。
<?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars_decode($str); ?>
上面代码的 HTML 输出如下:
<!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html>
结果是
看这个html代码是不是就很熟悉了,这个b标签是不是也很熟悉,你有没有想到什么?
是的,没错,这个函数可以将以及预定义好的html实体转换成字符,我们具体看看吧。
htmlspecialchars_decode() 函数把一些预定义的 HTML 实体转换为字符。
会被解码的 HTML 实体是:
& 解码成 & (和号)
" 解码成 " (双引号)
' 解码成 ' (单引号)
> 解码成 > (大于)
那我们来看看他的语法吧。
htmlspecialchars_decode(string,flags)
就说到这里了,有其他想知道的,可以点击这个哦。→ →php视频教程
The above is the detailed content of Convert HTML entities to characters using php function. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools