Rev 130 Rev 139
Line 1... Line 1...
1 <?PHP 1 <?PHP
2 // +----------------------------------------------------------------------+ 2 // +----------------------------------------------------------------------+
3 // | PHP Version 4 | 3 // | PHP Version 4 |
4 // +----------------------------------------------------------------------+ 4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1997-2004 The PHP Group | 5 // | Copyright (c) 1997-2004 The PHP Group |
6 // +----------------------------------------------------------------------+ 6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 3.0 of the PHP license, | 7 // | This source file is subject to version 3.0 of the PHP license, |
8 // | that is bundled with this package in the file LICENSE, and is | 8 // | that is bundled with this package in the file LICENSE, and is |
9 // | available at through the world-wide-web at | 9 // | available at through the world-wide-web at |
10 // | http://www.php.net/license/3_0.txt. | 10 // | http://www.php.net/license/3_0.txt. |
11 // | If you did not receive a copy of the PHP license and are unable to | 11 // | If you did not receive a copy of the PHP license and are unable to |
12 // | obtain it through the world-wide-web, please send a note to | 12 // | obtain it through the world-wide-web, please send a note to |
13 // | license@php.net so we can mail you a copy immediately. | 13 // | license@php.net so we can mail you a copy immediately. |
14 // +----------------------------------------------------------------------+ 14 // +----------------------------------------------------------------------+
15 // | Authors: Stephan Schmidt <schst@php.net> | 15 // | Authors: Stephan Schmidt <schst@php.net> |
16 // | Aidan Lister <aidan@php.net> | 16 // | Aidan Lister <aidan@php.net> |
17 // +----------------------------------------------------------------------+ 17 // +----------------------------------------------------------------------+
18 // 18 //
19 // $Id: htmlspecialchars_decode.php,v 1.3 2005/06/18 14:02:09 aidan Exp $ 19 // $Id: htmlspecialchars_decode.php,v 1.3 2005/06/18 14:02:09 aidan Exp $
20   20  
21   21  
22 /** 22 /**
23 * Replace function htmlspecialchars_decode() 23 * Replace function htmlspecialchars_decode()
24 * 24 *
25 * @category PHP 25 * @category PHP
26 * @package PHP_Compat 26 * @package PHP_Compat
27 * @link http://php.net/function.htmlspecialchars_decode 27 * @link http://php.net/function.htmlspecialchars_decode
28 * @author Aidan Lister <aidan@php.net> 28 * @author Aidan Lister <aidan@php.net>
29 * @version $Revision: 1.3 $ 29 * @version $Revision: 1.3 $
30 * @since PHP 5.1.0 30 * @since PHP 5.1.0
31 * @require PHP 4.0.0 (user_error) 31 * @require PHP 4.0.0 (user_error)
32 */ 32 */
33 if (!function_exists('htmlspecialchars_decode')) { 33 if (!function_exists('htmlspecialchars_decode')) {
34 function htmlspecialchars_decode($string, $quote_style = null) 34 function htmlspecialchars_decode($string, $quote_style = null)
35 { 35 {
36 // Sanity check 36 // Sanity check
37 if (!is_scalar($string)) { 37 if (!is_scalar($string)) {
38 user_error('htmlspecialchars_decode() expects parameter 1 to be string, ' . 38 user_error('htmlspecialchars_decode() expects parameter 1 to be string, ' .
39 gettype($string) . ' given', E_USER_WARNING); 39 gettype($string) . ' given', E_USER_WARNING);
40 return; 40 return;
41 } 41 }
42   42  
43 if (!is_int($quote_style) && $quote_style !== null) { 43 if (!is_int($quote_style) && $quote_style !== null) {
44 user_error('htmlspecialchars_decode() expects parameter 2 to be integer, ' . 44 user_error('htmlspecialchars_decode() expects parameter 2 to be integer, ' .
45 gettype($quote_style) . ' given', E_USER_WARNING); 45 gettype($quote_style) . ' given', E_USER_WARNING);
46 return; 46 return;
47 } 47 }
48   48  
49 // Init 49 // Init
50 $from = array('&amp;', '&lt;', '&gt;'); 50 $from = array('&amp;', '&lt;', '&gt;');
51 $to = array('&', '<', '>'); 51 $to = array('&', '<', '>');
52 52
53 // The function does not behave as documented 53 // The function does not behave as documented
54 // This matches the actual behaviour of the function 54 // This matches the actual behaviour of the function
55 if ($quote_style & ENT_COMPAT || $quote_style & ENT_QUOTES) { 55 if ($quote_style & ENT_COMPAT || $quote_style & ENT_QUOTES) {
56 $from[] = '&quot;'; 56 $from[] = '&quot;';
57 $to[] = '"'; 57 $to[] = '"';
58 58
59 $from[] = '&#039;'; 59 $from[] = '&#039;';
60 $to[] = "'"; 60 $to[] = "'";
61 } 61 }
62   62  
63 return str_replace($from, $to, $string); 63 return str_replace($from, $to, $string);
64 } 64 }
65 } 65 }
66   66  
67 ?> 67 ?>
68 68