Ampersand weirdnessess.

L

Louster

Guest
This place is pretty much dead, but I don't know any better place to post this, so...

I've found that, when translating text using the combination of strtr and get_html_translation_table, I get some weird... things going on when trying to convert '&' characters.

Ok, here's a code snippet:
Code:
    $txttohtml = get_html_translation_table( HTML_ENTITIES );
    printf( "%s\n", strtr( "&", $txttohtml ) );
    $txttohtml = get_html_translation_table( HTML_ENTITIES, ENT_NOQUOTES );
    printf( "%s\n", strtr( "&", $txttohtml ) );
    $txttohtml = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );
    printf( "%s\n", strtr( "&", $txttohtml ) );

The output is:
Code:
'
"
&
(Actually the output isn't that, but BW doesn't prevent the html codes from being changed into the characters they represent.)

The output is the same with HTML_SPECIALCHARS.
Is this supposed to happen? I can't see any link between specifying whether or not it translates quotes to codes and what it translates ampersands to... It doesn't make sense I tells ya!
 
S

ShockingAlberto

Guest
i gues i dont know enough about html to help ye :/

this place isn't really dead, if you post people will reply, its just no-one starts any threads/disscussions
 
L

Louster

Guest
Hehe! I only just noticed the 'PHP' tag thing. So let's try out something.
PHP:
    $txttohtml = get_html_translation_table( HTML_ENTITIES );
    printf( "%s\n", strtr( "&", $txttohtml ) );
    $txttohtml = get_html_translation_table( HTML_ENTITIES, ENT_NOQUOTES );
    printf( "%s\n", strtr( "&", $txttohtml ) );
    $txttohtml = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );
    printf( "%s\n", strtr( "&", $txttohtml ) );

Neato. Shame it looks rubbish, and the formatting is screwed up. But apart from that, neato. Neato!!! NEATO I SAY!
 

Users who are viewing this thread

Top Bottom