moby04 Posted July 26, 2007 Share Posted July 26, 2007 I've got a problem with recursion function in PHP. The code I've written does nothing and ofcourse I know how to fix it but I have found a certain problem. The code is: <?php function reverse($string) { if(strlen($string)>0) reverse($string); //should be: reverse(substr($string, 1)); echo substr($string, 0, 1); return; } reverse("Hello"); ?> When I try to run it from localhost (I use Apache2 na Ubuntu 7.04 z PHP 5.2.1, script run at Firefox 2.0.0.5) my browser displays file download form insted of HTML result. At the begining I thought it is the problem with the neverending recursion but when I tried with the following code everything was fine (it breaked at value of 18271): <?php function rekurencja() { static $i = 1; echo $i++."<br />\n"; rekurencja(); return; } rekurencja("Hello"); ?> I asked already at polish forum but I had no answer (rekurencja is just a recursion ). Can you tell me what is the problem? Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 26, 2007 Share Posted July 26, 2007 IT is because PHP isn't installed properly on your computer. I used to have the same problem. Reinstall carefully and it should be fixed. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 26, 2007 Share Posted July 26, 2007 The above poster is correct, I just wanted to ask what was wrong with the built in string-reversal function? http://www.php.net/manual/en/function.strrev.php Quote Link to comment Share on other sites More sharing options...
moby04 Posted July 27, 2007 Author Share Posted July 27, 2007 I have my php installed by synaptic along with Apache... Should I remove it and install from the sources? Quote Link to comment Share on other sites More sharing options...
moby04 Posted July 27, 2007 Author Share Posted July 27, 2007 The above poster is correct, I just wanted to ask what was wrong with the built in string-reversal function? http://www.php.net/manual/en/function.strrev.php Nothing's wrong ofcourse. I just wanted to try it this way and went into a problem. That's all. 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.