Jump to content

One of the strangest things...ever


johnnyk

Recommended Posts

PHP Version 5.1.4

This 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!!!!
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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>";
}
?>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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  :o

and 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.
Link to comment
Share on other sites

...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 time

I'm an idiot. But it's late at night, so you can't blame me too much.
Link to comment
Share on other sites

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 ok

bla bla ...............
Link to comment
Share on other sites

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'";

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.