WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Convert special characters for display in HTML
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.
$data: String to be formatted
String with certain characters replaced. The translations performed are:
| CHARACTER | NAME | TRANSLATED (HTML ENTITY) |
|---|---|---|
| & | ampersand | & |
| “ | double quote | " |
| ' | single quote | ' |
| < | less than | < |
| > | greater than | > |
<? $data="<a href='test'>Test</a>" $send=htmlspecialchars($data); print($send); ?>
The above example will set $send to the value <a href='test'>Test</a> and the browser will display:
<a href='test'>Test</a>
(Without conversion by htmlspecialchars the browser would instead display the hyperlink Test)
<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>