diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-29 12:05:52 -0500 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-29 12:05:52 -0500 |
commit | 9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d (patch) | |
tree | c1664acb781f7ca6de2b99429d2c43274d96f42c /phpBB/includes/functions.php | |
parent | 83e85810aa7b04b992c8c24ec8b2eac700c4594e (diff) | |
download | forums-9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d.tar forums-9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d.tar.gz forums-9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d.tar.bz2 forums-9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d.tar.xz forums-9c0a03f1d56d069a5ca5092de8e0f3e4e6ee9c1d.zip |
[ticket/11095] Python quoteattr port.
PHPBB3-11095
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r-- | phpBB/includes/functions.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d7088ac129..5d8a92b63b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4894,6 +4894,53 @@ function phpbb_http_login($param) } /** +* Escapes and quotes a string for use as an HTML/XML attribute value. +* +* This is a port of Python xml.sax.saxutils quoteattr. +* +* The function will attempt to choose a quote character in such a way as to +* avoid escaping quotes in the string. If this is not possible the string will +* be wrapped in double quotes and double quotes will be escaped. +* +* @param string $data The string to be escaped +* @param array $entities Associative array of additional entities to be escaped +* @return string Escaped and quoted string +*/ +function phpbb_quoteattr($data, $entities = null) +{ + $data = str_replace('&', '&', $data); + $data = str_replace('>', '>', $data); + $data = str_replace('<', '<', $data); + + $data = str_replace("\n", ' ', $data); + $data = str_replace("\r", ' ', $data); + $data = str_replace("\t", '	', $data); + + if (!empty($entities)) + { + $data = str_replace(array_keys($entities), array_values($entities), $data); + } + + if (strpos($data, '"') !== false) + { + if (strpos($data, "'") !== false) + { + $data = '"' . str_replace('"', '"', $data) . '"'; + } + else + { + $data = "'" . $data . "'"; + } + } + else + { + $data = '"' . $data . '"'; + } + + return $data; +} + +/** * Generate page header */ function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') |