rhyspaterson Posted May 29, 2007 Share Posted May 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/ Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 PHP is parsed on the server, not the client (browser). Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264345 Share on other sites More sharing options...
MadTechie Posted May 29, 2007 Share Posted May 29, 2007 its output that the browser used the code is parsed by the server... most common problem is javascript in FF to IE7 Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264347 Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264348 Share on other sites More sharing options...
MadTechie Posted May 29, 2007 Share Posted May 29, 2007 check the input.. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264350 Share on other sites More sharing options...
Psycho Posted May 29, 2007 Share Posted May 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264351 Share on other sites More sharing options...
rhyspaterson Posted May 30, 2007 Author Share Posted May 30, 2007 Yeah have been checking the source over and over. There is literally no output. But i will keep checking, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264362 Share on other sites More sharing options...
Psycho Posted May 30, 2007 Share Posted May 30, 2007 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!"; } } Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264400 Share on other sites More sharing options...
AndyB Posted May 30, 2007 Share Posted May 30, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264420 Share on other sites More sharing options...
rhyspaterson Posted May 30, 2007 Author Share Posted May 30, 2007 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 ^^ Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264438 Share on other sites More sharing options...
AndyB Posted May 30, 2007 Share Posted May 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53479-solved-code-working-in-firefox-but-not-ie-7/#findComment-264442 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.