• PHP Video Tutorials

PHP - Function Htmlspecialchars



Syntax

string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 
   [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )

Definition and Usage

It is used to convert special characters to HTML entities

Return Values

It returns the converted string.

Parameters

Sr.No Parameters & Description
1

string

It contains the information about input string

2

flags

It contains the information about flags

3

encoding

It is an optional argument defining the encoding used when converting characters.

Example

Try out the following example

<?php
   $input = htmlspecialchars("<a href='tutorialspoint'>Tutorialspoint</a>", ENT_QUOTES);
   
   echo $input;
?>

This will produce following result − −

<a href='tutorialspoint'>Tutorialspoint</a>
php_function_reference.htm
Advertisements