Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts

    Exclamation htmlspecialchars()

    I'm trying to execute this code...it's straight out of the PHP manual:

    PHP Code:
    $new htmlspecialchars("<a href='test'>Test</a>"ENT_QUOTES);
    echo 
    $new
    This outputs:

    <a href='test'>Test</a>
    I'm running PHP 5....is there some reason that htmlspecialchars() is not working here....a setting in the php.ini perhaps? I'm ready to pull my hair out over this, it doesn;t make sense...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #2
    New Coder dragon's Avatar
    Join Date
    May 2003
    Location
    Florida
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The echo is sending the output to the browser, so the browser is interpreting it correctly. Is this the output that the browser is displaying or the source code of the html?
    Last edited by dragon; 02-19-2006 at 10:23 AM.

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    huh? I was under the impression that the output should be as it is on the following page (look for the example, it's identical): http://us2.php.net/manual/en/functio...ecialchars.php

    what I've shown here is what the browser is outputing...there is no "HTML source code" involved here, this is purely PHP...my file consists of these 2 lines and nothing else...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    New Coder dragon's Avatar
    Join Date
    May 2003
    Location
    Florida
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you viewing the output through a browser though? The browser will interpret the ASCII into what you're seeing as output. Right-click on the browser and view source. Alternatively, try sending the output directly to a text file and then read it from there.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or you could try the <xmp> tag - it's not valid or standard, but some browsers implement it and it's useful for testing - it outputs literal code, exactly as it appears in source:
    PHP Code:
    echo('<xmp>');
    var_dump($new);
    echo(
    '</xmp>'); 
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try...

    http://us2.php.net/manual/en/function.htmlentities.php

    PHP Code:
    <?php
    $str 
    "A 'quote' is <b>bold</b>";

    // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str);

    // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($strENT_QUOTES);
    ?>

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Sorry, guys, you were right....the browser interpreted the ascii and rendered the HTML...if I view source, everything has been encoded correctly...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •