Adding SafeString::for_html_attr()

This commit is contained in:
Andy Staudacher
2009-08-29 11:48:55 -07:00
parent 1d633457c4
commit 7adb9ea2e3
2 changed files with 33 additions and 7 deletions

View File

@@ -89,6 +89,25 @@ class SafeString_Core {
return self::_escape_for_js($this->_raw_string);
}
/**
* Safe for use in HTML element attributes.
*
* Assumes that the HTML element attribute is already
* delimited by single or double quotes
*
* Example:<pre>
* <a title="<?= $php_var->for_html_attr() ?>">;
* </script>
* </pre>
* @return the string escaped for use in HTML attributes.
*/
function for_html_attr() {
$string = (string) $this->for_html();
return strtr($string,
array("'"=>"&#039;",
'"'=>'&quot;'));
}
/**
* Safe for use HTML (purified HTML)
*