January 24th, 2013, 10:01 AM
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.
$str = "\x8F!!!";
// Outputs an empty string
echo htmlentities($str, ENT_QUOTES, "UTF-8");
// Outputs "!!!"
echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8");
January 24th, 2013, 10:16 AM
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.
January 24th, 2013, 10:22 AM
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?
To be used in:
$selected = (isset($_POST['mo']) && $_POST['mo'] == $i) || (!isset($_POST['mo']) && $i == $current_date['mon']);
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. :-/
<option value="' . $i . '"' . ($selected ? ' selected="selected"' : '') . '>
January 24th, 2013, 10:37 AM
$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.
January 24th, 2013, 10:59 AM