johnnyk Posted July 1, 2006 Share Posted July 1, 2006 PHP Version 5.1.4This is weird and annoying and pissing me off.if('2006' == '2005'){ echo "<div class=\"class\">\n"; echo "<h5 class=\"class\">text</h5><.br />\n"; echo "</div>\n";}(I added the . to the <.br /> because this new forum is evil)The if executes. Am I missing something obvious? Honestly, what the curse? This is the strangest PHP related problem I've ever had. Honestly, at this point if you told me it was executing because I'm not standing on my head I would believe you because I can't find any other reason.I had another weird problem the other day. MySQL kept saying there was an error in my SQL syntax when there wasn't. I even posted it on here and someone verified it was fine with the version of MySQL I was using, but MySQL kept bitching.So my question is, why do PHP and MySQL hate me? Or maybe my question is, why am I going crazy? This is like a PHP nightmare. Things are just going crazy for absolutely no reason at all. AHH!!!! Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/ Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 Try this you dont need to back slash while using double quotes do ya lol?if('2006' == '2005'){ echo "<div class='class'>"; echo "<h5 class='class'>text</h5><br>"; echo "</div>";}Also when you got the " double used then in the middile you use ' single , so double then single lol Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51528 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 yes you do need to use backslashes with double quotes, if you started out with double quotes. but that's not the point. the point is that php is deeming that if statement true. honestly i have no clue why... Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51529 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 I tested it this way and works fine.<?$a="2005";$b="2006";if($b>$a){ echo "<div class='class'>"; echo "<h5 class='class'>text</h5>"; echo "</div>";}?>this also works fine<?$a="2005";$b="2006";if($b==$a){ echo "<div class='class'>"; echo "<h5 class='class'>text</h5>"; echo "</div>";}?> Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51531 Share on other sites More sharing options...
johnnyk Posted July 1, 2006 Author Share Posted July 1, 2006 It only gets screwed up in a certain script of mine. If I isolate the if into its own php script it works fine.Is there any possibility that somehow the rest of my script is affecting the if? Is there any possibility it's a really strange bug? Is there any possibility my host is to blame?Something is cursed up here, but I have no idea what.Where's the smiley for "Head is about to explode"? Damn new forum. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51532 Share on other sites More sharing options...
Drumminxx Posted July 1, 2006 Share Posted July 1, 2006 so if you:if('2006' != '2005'){ echo "<div class=\"class\">\n"; echo "<h5 class=\"class\">text</h5><br />\n"; echo "</div>\n";}does it display nothing :oand redarrow,yes you do need need to escape double quotes in double quoted strings its single quoted strings that you do not need to escape double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51534 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 ok thank you so try single quotes then?cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51535 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 umm.. i guess post the rest of your code that surrounds it, cuz i tried it in an isolated example for shits and grins and it worked the way it should... Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51536 Share on other sites More sharing options...
johnnyk Posted July 1, 2006 Author Share Posted July 1, 2006 ...um, sorry people. It actually was working fine...I saw something coming up on the page and got confused and thought it was whats in the if......sorry to waste your timeI'm an idiot. But it's late at night, so you can't blame me too much. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51537 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 LMAO okay ;D Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51538 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 Crayon Violent a quick quistion how comes the code i posted in reply worked when it shouldnt as i have not added any \backslashes help lol.I see the ansaw know its becouse the oreganal code were the class has double qoutes are there and mine are single okbla bla ............... Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51539 Share on other sites More sharing options...
Drumminxx Posted July 1, 2006 Share Posted July 1, 2006 because you edited your post to reflect single quotes inside the double quotes, your original post would have terminated the strings and caused an error. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51540 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 what he said. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51541 Share on other sites More sharing options...
Drumminxx Posted July 1, 2006 Share Posted July 1, 2006 ;D Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51542 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 thank you.i got told from my teacher not to use double qoutes within double qoutesso does \escaping double qoutes work faster or is it a coding prefrence cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51545 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 it depends on the circumstance. if you were using quotes in a normal sentence structure, for example:The lady said, "How may I help you?"You would want to preserve the double quotes, so you would escape them:echo "The lady said, \"How may I help you?\"";When dealing with variables in a string, most the time it is easer to use double quotes. Why? because if you do this:[code=php:0]$blah = "foobar";echo "$blah";echo '$blah';[/code]The first echo will echo foobar, where as the 2nd echo will literally echo $blah. So, if you are, for instance, building a query string, well, values require quotes around them, in order for them to be valid in mysql. well, string values do, not numerical. But anyways, which do you think looks cleaner, this:$sql = "update table set blah = \"".$blah."\" where id = \"". $id . "\"";or this:$sql = "update table set blah = '$blah' where id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51550 Share on other sites More sharing options...
redarrow Posted July 1, 2006 Share Posted July 1, 2006 thanks for the reply.this$sql = "update table set blah = '$blah' where id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51553 Share on other sites More sharing options...
heckenschutze Posted July 1, 2006 Share Posted July 1, 2006 You don't need to quote integers, its bad practice for a start, eg if PHP wasn't so lenient, such as C for example, trying to compare strings as you were (arrays of characters) would result in many errors.Bad Practice:[code]if('2006' != '2005')[/code]Bad Practice:[code]if("2006" != "2005")[/code]Good Practice:[code]if(2006 != 2005)[/code]And using quotes inside your strings will NOT slow down the parsing of your script... Quote Link to comment https://forums.phpfreaks.com/topic/13358-one-of-the-strangest-thingsever/#findComment-51582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.