Jump to content

Recommended Posts

Hey guys,

 

I have some code that seems to be processed by Firefox (v 2.0.0.3) but not IE7 (v 7.0.530.11). This is the first time i have ever encountered something like this before and was just wondering if you guys could shed any light..

 


$arrayText is an array
$lineNumber is an integer (initialized as 0.. used to just count upwards)
$userToEditLength is an integer (the length of a username)
$userToEdit is the name of the user i want to edit (such as 'bob', 'mary' ect)

foreach ($arrayText as $t) {
  $lineNumber = $lineNumber + 1;
      if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") {

// Firefox returns the IF statement as true, but IE7 does not. The IF statement *should* be returned as true but it seems IE7 is not parsing it correctly..

      }

 

Any suggestions guys.. hope i explained by code as much as necessary.

 

Thanks heaps.

That's what i thought! However if i put an echo statement in there, Firefox returns it and the variables i initialize in it, but IE7 does not.. I.e

 

  foreach ($arrayText as $t) {
  $lineNumber = $lineNumber + 1;
      if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") {
 echo "Huzzah! It works!";
 echo $lineNumber;
}

 

FF returns both, IE7 returns nothing. Hmm.

The HTML code output before and after those echos can prevent the text from being "displayed" in the browser. you need to check the HTML source code within your browser to verfy that the text is being written tot he page, which I am sure it is.

Ok, you have a hypothesis as to why the prolem exists. Your next step is to try and disprove or prove the hypothesis. There is a very simple test you can do to either prove or dispriove your hypothesis.

 

Use an ELSE clause. If IE is interpreting the IF statement as false then test it:

 

foreach ($arrayText as $t) {
  $lineNumber = $lineNumber + 1;
  if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") {
    echo "Huzzah! It works!";
    echo $lineNumber;
  } else {
    echo "It didn't work Watson!";
  }
}

A web server doesn't have a clue about what browser is going to be used to render the html generated by the php script.  It 'it works' with browser A but not with browser B it has nothing to do with the php script and everything to do with the generated html output.

 

You are running this from a web server not simply executing it by opening the script locally in a browser aren't you?

Hi guys,

 

After a large amount of debugging i figured out what was going on. To answer some questions, yes, this is running on a remote webserver, not locally.

 

What appears to be happening, is when IE7 reads in my $userToEdit field, it's just inserting a space after it. Firefox on the other hand is not.

 

echo "The user to edit is: '$userToEdit'"t;

//FF output is: The user to edit is: 'Dr Watson';

//IE output is: The user to edit is: 'Dr Watson ';

// therefore we must run a trim command to get rid of the space

$userToEdit = trim($userToEdit);

// and make changes to substr command by addition of OR pipes

foreach ($arrayText as $t) {
          $lineNumber = $lineNumber + 1;
	  
	  // note the differences (-1 and 0)
	  
          if ((substr($t, 0, $userToEditLength -1) == "<n>$userToEdit") || (substr($t, 0, $userToEditLength) == "<n>$userToEdit")) {

          // run commands

          }
}

 

I'm just curious why this happens. The $userToEdit field is 100% plain text. Not special characters and no spaces.. *shrug*

 

Thanks for all your suggestions guys ^^

Color me baffled:

 

$var =  "banana";

include("guess_browser_module.php");

echo $var; // different depending on whether server guesses what browser will render the code

 

when IE7 reads ... implies that the root cause of the problem is how the data are provided to the php script, not what the php script does with the data.  That suggests it's your input method that's the root cause of this behaviour, not the script or browser.

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.