User Tools

Site Tools


uphp:functions:htmlspecialchars

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
uphp:functions:htmlspecialchars [2017/04/11 10:56]
jeff created
uphp:functions:htmlspecialchars [2021/09/13 05:57] (current)
Line 7: Line 7:
 ====Description==== ====Description====
  
-<well size="sm"> +<well size="sm"><html>
-<html>+
 <span style="font-size:125%;color:green">string <span style="font-size:125%;color:green">string
-<span style="color:black"> +<span style="color:black">htmlspecialchars (
-</html> +
-[[htmlspecialchars]] ( +
-<html>+
 <span style="color:green">string <span style="color:green">string
 <span style="color:blue">$data <span style="color:blue">$data
 <span style="color:black">) <span style="color:black">)
-</html> +</html></well>
-</well>+
  
-Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with these conversions made.+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==== ====Parameter====
  
-<html><b><span style="color:blue">$data<span style="color:black"></b></html>:  <html><b><span style="color:green">String<span style="color:black"></b></html> to be formatted+<html><b><span style="color:blue">$data<span style="color:black"></b>:  <b><span style="color:green">String<span style="color:black"></b> to be formatted</html>
  
-====Return Value====+====Return Values====
  
-<html><b><span style="color:green">String<span style="color:black"></b></html> with certain characters replaced. The translations performed are:+<html><b><span style="color:green">String<span style="color:black"></b> with certain characters replaced. The translations performed are:</html>
  
 ^CHARACTER^NAME^TRANSLATED (HTML ENTITY)^ ^CHARACTER^NAME^TRANSLATED (HTML ENTITY)^
-|&|ampersand|&amp;+|&|ampersand|''&amp;''
-|"|double quote|&quot;+|"|double quote|''&quot;''
-|'|single quote|&#039;+|'|single quote|''&#039;''
-|<|less than|&lt;+|<|less than|''&lt;''
-|>|greater than|&gt;|+|>|greater than|''&gt;''|
  
-====Example====+====Examples====
  
 <code php> <code php>
Line 43: Line 38:
   $data="<a href='test'>Test</a>"   $data="<a href='test'>Test</a>"
   $send=htmlspecialchars($data);   $send=htmlspecialchars($data);
 +  print($send);
 ?> ?>
 </code> </code>
  
-The above example will set $send to the value ''&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;''+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: 
 + 
 +<code> 
 +<a href='test'>Test</a> 
 +</code> 
 + 
 +(Without conversion by [[htmlspecialchars]] the browser would instead display the hyperlink <html><span style="color:blue"></html>__Test__<html><span style="color:black"></html>
 + 
 +===Read the file index.cgi line by line and format the output for display on the browser screen=== 
 + 
 +<code php> 
 +<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> 
 +</code>
  
uphp/functions/htmlspecialchars.1491908164.txt.gz · Last modified: 2021/09/13 05:56 (external edit)