Thanks,

I'll give it a whrrrl :)

Justin




on 08/01/03 4:05 PM, Greg Beaver ([EMAIL PROTECTED]) wrote:

> Hi Justin,
> 
> You have to specify the list of tags you want preserved in an array, but
> this function from phpDocumentor will do it:
> 
> /**
> * smart htmlentities, doesn't entity the allowed tags list
> * Since version 1.1, this function uses htmlspecialchars instead of
> htmlentities, for international support
> * @param string $s
> * @return string browser-displayable page
> */
> function adv_htmlentities($s,$html_allowed)
> {
> $___htmltemp = array_flip($html_allowed);
> $___html1 = array();
> foreach($___htmltemp as $tag => $trans)
> {
> $___html1['<'.$tag.'>'] = htmlentities('<'.$tag.'>');
> $___html1['</'.$tag.'>'] = htmlentities('</'.$tag.'>');
> }
> $_html = array_flip($___html1);
> }
> $result = htmlspecialchars($s);
> $entities = array_flip(get_html_translation_table(HTML_SPECIALCHARS));
> $result = strtr($result,$_html);
> $matches = array();
> preg_match_all('/(&lt;img.*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> preg_match_all('/(&lt;font.*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> preg_match_all('/(&lt;ol.*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> preg_match_all('/(&lt;ul.*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> preg_match_all('/(&lt;li.*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> preg_match_all('/(&lt;a .*&gt;)/U',$result,$matches);
> for($i=0;$i<count($matches[1]);$i++)
> {
> $result =
> str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_transl
> ation_table(HTML_SPECIALCHARS))),$result);
> }
> return $result;
> }
> 
> Regards,
> Greg
> --
> phpDocumentor
> http://www.phpdoc.org
> "Justin French" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>> Hi all,
>> 
>> Has anyone got a function or regexp floating around that will convert
> behave
>> like htmlspecialchars() or htmlentities() (eg converting & to &amp;, " to
>> &quote;, etc etc) BUT NOT DESTROY HTML TAGS?
>> 
>> Eg:
>> 
>> "hello" said <a href="fred.php">Fred</a> & Judy
>> 
>> should become:
>> 
>> &quot;hello&quot; said <a href="fred.php">Fred &amp; Judy
>> 
>> NOT:
>> &quot;hello&quot; said &lt;a href=&quot;fred.php&quot;&gt;Fred &amp; Judy
>> 
>> ????
>> 
>> I guess it's stripped down or limited version of htmlspecialchars() or
>> htmlentities().
>> 
>> 
>> Justin
>> 
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to