1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

function htmlentities()

Discussion in 'PHP' started by php-linux, Jun 30, 2007.

  1. #1
    Hi,
    I work with a ubuntu system and php 5.2.1.
    The next code doesn't convert special characters and html codes to entities!
    <html>
    <head>
    <title>Text including html</title>
    </head>
    
    <body>
    <?php
    echo phpinfo();
    $str= <<<TEXT
    Einstürzende Neubauten and Marya's & <br>Mother and again "test".
    TEXT;
    $code=htmlentities($str, ENT_QUOTES);
    $code1=htmlspecialchars($str);
    echo $code,"<br>",$code1;
    ?>
    </body>
    
    </html>
    Code (markup):
    The output of the code is:
    Could you tell me why my code doesn't work?

    Thanks,
     
    php-linux, Jun 30, 2007 IP
  2. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    wow, that's interesting.. I'm still working on my Fedora 7 with the internet now.. haha... but try to use print instead of echo, and also, try to use <br />
     
    ProgrammersTalk, Jun 30, 2007 IP
  3. php-linux

    php-linux Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The result is:
     
    php-linux, Jun 30, 2007 IP
  4. php-linux

    php-linux Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Solved! :D
     
    php-linux, Jun 30, 2007 IP
  5. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just for referance.. print() is just an alias of echo() ;)

    Also care to explain how you fixed it? Might as well in case someone else has the same issue and stumbles upon this thread.
     
    CodyRo, Jun 30, 2007 IP
  6. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i think he just had to change the charset encoding of his html page to UTF-8 or UTF-16.

    And print is not really an alias of echo: echo is a php language construct while print is a php function. To outcome is exactly the same, but it's a different type
     
    UnrealEd, Jun 30, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    actually, both print() and echo() are language constructs. the only significant difference is that print() has the ability to span across multiple lines without concatenating unlike echo().
     
    ansi, Jun 30, 2007 IP
  8. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Oops :)
    Thanks for clearing that up. I always thought print was a function.
     
    UnrealEd, Jul 1, 2007 IP