Scutterman Posted March 19, 2008 Share Posted March 19, 2008 Ok, I have just started to learn PHP and AJAX. I have been meaning to learn for a while, but I kind of forced myself to learn by creating a chatroom out of them. It was easier than i thought, since I found a pre-made code, and since php is so similar to javascript I found it easy enough to mod. Everything was fine, until I decided to try and add in bb code. I wrote the following function: function foo_bb($searchFor, $out1){ // $foo_now will store the string that will replace the bb code // set it to bold for the first one $foo_now = "font-weight: bold;"; // replace the bb code with html code for bold while (strpos($out1, "[".$searchFor."]") != FALSE && strpos($out1, "[/".$serarchFor."]") != FALSE) { $out1 = str_ireplace("[".$searchFor."]","<span style=".$foo_now.">", $out1); $out1 = str_ireplace("[/".$searchFor."]","</span">", $out1); } // set $foo_now to underline $foo_now = "text-decoration: underline;"; // search for underline bb code $searchFor = "u"; // replace the bb code with html code for underline while (strpos($out1, "[".$searchFor."]") != FALSE && strpos($out1, "[/".$serarchFor."]") != FALSE) { $out1 = str_ireplace("[".$searchFor."]","<span style=".$foo_now.">", $out1); $out1 = str_ireplace("[/".$searchFor."]","</span">", $out1); } // set $foo_now to italic $foo_now = "font-style: italic;"; // search for italic bb code $searchFor = "i"; // replace the bb code with html code for italic while (strpos($out1, "[".$searchFor."]") != FALSE && strpos($out1, "[/".$serarchFor."]") != FALSE) { $out1 = str_ireplace("[".$searchFor."]","<span style=".$foo_now.">", $out1); $out1 = str_ireplace("[/".$searchFor."]","</span">", $out1); } // return the modified message return $out1; } and I call it using: $out = foo_bb("b",$out); The php file has been called using AJAX xml http requests: xhr.open("GET", "data2.php?m=" + message + "&c=" + txtColor + "&t=" + time1 + "&g=" + time2, true); xhr.send(null); all variables passed to the php function are correct, and xhr is what has been used to set up the request ok. A few facts. * I have gone through at least half a dozen tutorials, and I cannot see what's wrong with the function. * If I comment out the parts that call the function, I get the same error. I need to comment out the function itself to get the chatroom working again. * The only error is from the xhr.status, which I have displaying whenever the status is not 200. The error is 500 [server] which, in combination with everything else, lead me to believe that the function is the problem. The source files are: php file: http://scutterman.com/help/data.txt html file: http://scutterman.com/help/index.htm.txt ok, I think that's about it... I hope that is enough detail, without being overly complex... TIA ~~Scutterman~~ Quote Link to comment Share on other sites More sharing options...
Scutterman Posted March 19, 2008 Author Share Posted March 19, 2008 *bump* Quote Link to comment Share on other sites More sharing options...
Scutterman Posted March 20, 2008 Author Share Posted March 20, 2008 *bump* Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 20, 2008 Share Posted March 20, 2008 your function won't compile as written. if you're not seeing that error, you should ensure error_reporting is turned on. i suggest that you use a text editor that will highlight 'off' areas in a different color so you can see, for instance, where you have a double-quote and shouldn't have one. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 20, 2008 Share Posted March 20, 2008 It can be really hard to debug server side scripts invoked via XHR. The best thing to do is create a test script that calls the code invoked via XHR to make sure it is working correctly. Then use it for your actual XHR requests. Quote Link to comment Share on other sites More sharing options...
Scutterman Posted March 20, 2008 Author Share Posted March 20, 2008 Okay, thanks. I've got psPad now, and I saw the problem in a few minutes. Thanks for the help ummm... I saw something about a "Solved" button, but I can't see it?? where abouts is it? ~~Scutterman~~ Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 20, 2008 Share Posted March 20, 2008 It was removed when the forums were upgraded, not sure when it's coming back. Quote Link to comment Share on other sites More sharing options...
Scutterman Posted March 20, 2008 Author Share Posted March 20, 2008 ah, okay. well, I hope to be here alot more in future, seems like a really nice community. ~~Scutterman~~ Quote Link to comment 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.