search
Homephp教程PHP开发Definition and usage of php htmlentities() function

php htmlentities() function converts characters into HTML entities. This article introduces the basic usage and examples of the php htmlentities() function to coders. Coders in need can refer to it.

Definition and usage

htmlentities() function converts characters into HTML entities.

Tip: To convert HTML entities back to characters, use the html_entity_decode() function.

Tip: Please use the get_html_translation_table() function to return the translation table used by htmlentities().

Syntax

htmlentities(string,flags,character-set,double_encode)

php htmlentities()函数的定义和用法

##Technical details

php htmlentities()函数的定义和用法

Example 1

Convert characters to HTML entities:

<?php
$str = "Bill & &#39;Steve&#39;";
echo htmlentities($str, ENT_COMPAT); // 只转换双引号
echo "<br>";
echo htmlentities($str, ENT_QUOTES); // 转换双引号和单引号
echo "<br>";
echo htmlentities($str, ENT_NOQUOTES); // 不转换任何引号
?>

The HTML output of the above code is as follows (view Source code):

<!DOCTYPE html>
<html>
<body>
Bill & &#39;Steve&#39;<br>
Bill & &#39;Tarzan&#39;<br>
Bill & &#39;Steve&#39;
</body>
</html>

Browser output of the above code:

Bill & &#39;Steve&#39;
Bill & &#39;Steve&#39;
Bill & &#39;Steve&#39;

Example 2

Convert some characters to HTML entities by using Western European character sets:

<?php
$str = "My name is ?yvind ?sane. I&#39;m Norwegian.";
echo htmlentities($str, ENT_QUOTES, "ISO-8859-1");
// Will only convert double quotes (not single quotes), and uses the character-set Western European
?>

The HTML output of the above code is as follows (view source code ):

<!DOCTYPE html>
<html>
<body>
My name is Øyvind Åsane. I&#39;m Norwegian.
</body>
</html>

Browser output of the above code:

My name is ?yvind ?sane. I'm Norwegian.


The definition and usage of the php htmlentities() function above are all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

For more articles related to the definition and usage of the php htmlentities() function, please pay attention to the PHP Chinese website!


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version