Re: Re: Counterpart to htmlentities function: unhtmlentities

From: Date: Wed, 27 Feb 2002 03:56:35 +0000
Subject: Re: Re: Counterpart to htmlentities function: unhtmlentities
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-80429@lists.php.net to get a copy of this message
Not as trivial as you make it seem... ------------- Consider the following code: ----- $data = "This is &amp; some &#32; text"; $trans = get_html_translation_table(HTML_ENTITIES); $trans = array_flip($trans); $data2 = strtr($data,$trans); echo "Original data is:\n"; echo "$data\n\n"; echo "New data is:\n"; echo $data2; -------------- The output is: ------------------ Original data is: This is &amp; some &#32; text New data is: This is & some &#32; text ----------------------------------------------- Yes, the &amp; entity was handled properly, but the &#32; entity was not. That is a valid entity AFAIK. In addition to the speed improvement of having a native C version of this function, I think it would be worthwhile to have built-in. -Brad Rasmus Lerdorf wrote: > Reversing htmlentities is trivial. I don't think it needs a special > function. > > Simply do: > > $trans = get_html_translation_table(HTML_ENTITIES); > $trans = array_flip($trans); > $data = strtr($data,$trans); > > -Rasmus > > On Tue, 26 Feb 2002, Brad Fisher wrote: > > > > > I have looked at the following: > > http://www.php.net/anoncvs.php > > http://cvs.php.net/cvs.php > > > > I am rather new to CVS, so perhaps this is a stupid question... I > don't see > > the HEAD branch anywhere... Can I check it out through anon CVS or > would I > > need dev access? Or is this a reference to php4? > > > > Perhaps I am just not looking in the right place. > > > > -Brad > > > > Yasuo Ohgaki wrote: > > > > > Brad Fisher wrote: > > > > Just another function I have found useful.. PHP has a > htmlentities > > > > function, but no unhtmlentities function to go the other > direction.. (At > > > > least not that I am aware of). So, here you go. Don't think > this one > > > > would perform nearly as quickly if it were done using regexps in > PHP... > > > > This function also has the added benefit of supporting entities > like > > > > &#32; which I don't believe would be supported by a naive regexp > > > > > approach. > > > > > > > > So if someone would like to include it, be my guest. > > > > > > Could you post unified diff against latest CVS? (HEAD branch) > > > > > > We should have patch submit guide line in www.php.net for these > > > people who are willing to help project :) > > > > > > -- > > > Yasuo Ohgaki > > > > > > -- > > > PHP Development Mailing List > > > <http://www.php.net/> > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- > > PHP Development Mailing List <http://www.php.net/> > > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.dev (#80429) next »