#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7

    Htmlentities question


    I understand htmlentities generally, and have used them successfully so far. I just happen to have been reading the php.net page of it and cannot understand their 2nd example. The first echos out everything as I would expect, but I don't understand why the following 2nd example only focuses on the 3 !'s in the 2nd half. Where did the \x8F disappear to? Could anyone elaborate? Thank you.

    PHP Code:
    <?php
    $str 
    "\x8F!!!";

    // Outputs an empty string
    echo htmlentities($strENT_QUOTES"UTF-8");

    // Outputs "!!!"
    echo htmlentities($strENT_QUOTES ENT_IGNORE"UTF-8");
    ?>
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,874
    Rep Power
    6351
    It's because they're demonstrating ENT_IGNORE, which discards anything invalid. \x8F is not a valid code, so it's ignored. Without ENT_IGNORE, if the string is invalid you get NOTHING back, since it's assumed to be an attack or bad data.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Ah, okies. I wasn't thinking \x8F as a single item. And I dunno if I didn't get enough sleep last night or what, but I can't even really figure out this string I wrote. Anyone understand it?

    PHP Code:
    $selected = (isset($_POST['mo']) && $_POST['mo'] == $i) || (!isset($_POST['mo']) && $i == $current_date['mon']); 
    To be used in:

    PHP Code:
    <option value="' . $i  . '"' . ($selected ? ' selected="selected"' : '') . '
    I'm not seeing me make it equal 0/1, True/False, or anything. I see the checks like if this and that are equal to OR if this and that are equal, but never a then to define something. :-/
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    $selected is a boolean value created from combining conditions.

    Boolean values (true/false) and boolean operators (||, &&, ...) are normal values and operators. You can use them like any other value and operator.

    So instead of, say, 1 + 2 (which yields a number), you can write true || false (which yields true). It's the same thing.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo