SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow HELP !! htmlentities not working????

    i'm trying to use htmlentities, but it just doesn't work. I also tried htmlspecialchars and that doesn't work. Any advice????

    here's what i had:
    Code:
    <?php
    $sentence="This is the <title> of the book";
    $changeit = htmlentities($sentence);
    echo $changeit;
    ?>
    You know you cooler than me...

  2. #2
    SitePoint Zealot MajorTom's Avatar
    Join Date
    Aug 2007
    Location
    Planet earth
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure it's not working? If you are outputting the results with echo to an html page you won't see the entities on an html page unless you view the source of the html output.

  3. #3
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stuffedbuggy View Post
    i'm trying to use htmlentities, but it just doesn't work. I also tried htmlspecialchars and that doesn't work. Any advice????

    here's what i had:
    Code:
    <?php
    $sentence="This is the <title> of the book";
    $changeit = htmlentities($sentence);
    echo $changeit;
    ?>
    i changed it to this: and it worked...

    Code:
    <?php
    $sentence="This is the <title> of the book";
    $changeit = htmlentities($sentence);
    $newchange=htmlentities($changeit);
    echo $newchange;
    ?>
    You know you cooler than me...

  4. #4
    SitePoint Zealot MajorTom's Avatar
    Join Date
    Aug 2007
    Location
    Planet earth
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While the output in html appears to be correct, you're actually creating html entities of the html entities.

    Did you look at your html output source code like I recommended because what you're doing in the second example is creating source that looks like this

    Code:
    This is the &amp;lt;title&amp;gt; of the book
    I know it might be a bit confusing but try your first example and do a "view source" in your browser and see that the source is different from the output.


Bookmarks

Posting Permissions

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