NYCPHP Meetup

[nycphp-talk] Need an explanation as to what this line does...

Weston Houghton weslists at anapraxis.com
Sat Feb 1 17:04:56 EST 2003


Reading from inside out, here is what seems to be happening:

1. get_html_translation_table(HTML_ENTITIES)
This returns an associative array of the entities used in the  
HTML_ENTITIES translation table.

2. array_flip
This takes the associative array returned by get_html_translation_table  
above and swaps the values and keys of that array, so what was once a  
key is now a value.

3. strtr
In this case you are using the newer option for strtr that allows you  
to pass in an initial string ($stuffArray[$i][value]), and have the  
character values in that string translated based on the associative  
array returned by the array_flip step above.

So it looks to me like this line is converting translated entities into  
their original character counterpart. To see exactly what it is doing,  
try taking that same line:

> $stuffArray[$i][value] = strtr($stuffArray[$i][value],  
> array_flip(get_html_translation_table(HTML_ENTITIES)));

changing it to:

$oldString = "&lt;<this is a test>&gt;";
$newString = strtr($oldString,  
array_flip(get_html_translation_table(HTML_ENTITIES)));

And see how it comes out. I get:
<<this is a test>>

Wes



Essentially this is just converting characters in the string located at  
$stuffArray[$i][value] and replacing the old string with the newly  
"cleaned" string.

On Saturday, February 1, 2003, at 04:34  PM, Phil Powell wrote:

>  $stuffArray[$i][value] = strtr($stuffArray[$i][value],  
> array_flip(get_html_translation_table(HTML_ENTITIES)));
>
> To be bluntly honest, I don't understand hardly any of it, and the PHP  
> Manual isn't helping this time.. maybe I'm weekend-stupid or  
> something.. *sigh*
>
> Phil
>
>
>
> --- Unsubscribe at http://nyphp.org/list/ ---
>
>
>
>

------------------------------------------------------------------------ 
---
The selection and placement of letters on this page was
determined automatically by a computer program. Any
resemblance to actual words, sentences, or paragraphs is
pure coincidence, and no liability will be assumed for
such coincidences.
------------------------------------------------------------------------ 
---




More information about the talk mailing list