Table of Contents

htmlspecialchars

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Convert special characters for display in HTML

Description

string htmlspecialchars ( string $data )

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to be displayed in a browser “as is.” This function returns a string with these conversions made.

Parameter

$data: String to be formatted

Return Values

String with certain characters replaced. The translations performed are:

CHARACTERNAMETRANSLATED (HTML ENTITY)
&ampersand&
double quote"
'single quote'
<less than&lt;
>greater than&gt;

Examples

<?
  $data="<a href='test'>Test</a>"
  $send=htmlspecialchars($data);
  print($send);
?>

The above example will set $send to the value &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt; and the browser will display:

<a href='test'>Test</a>

(Without conversion by htmlspecialchars the browser would instead display the hyperlink Test)

Read the file index.cgi line by line and format the output for display on the browser screen

<pre><?
  $f=fopen("/index.cgi","r"); // open the file for reading and get the file handle
  if ($f) {
    while (!feof($f)) {
      print(htmlspecialchars(fgets($f))."\r\n"); // print the line to the screen
    }
  fclose($f); // close the file referenced by file handle
  } else {
    print("Unable to open file /index.cgi");
  }
?></pre>