
August 16th, 2004, 12:33 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
custom function not returning a string
Hello All,
I implemented a recursive method that removes padding from a string. When I output the string just before the return statement, the string is what I want it to be. However, it seems that the function is not returning the string. Here is the method I implemented, which is defined in the file functions.inc.php
PHP Code:
function removeLeftPadding ($str, $strRemove) { if ( (strcmp(substr($str, 0, 1), $strRemove) == 0) && (strlen($str) != 1) ) { removeLeftPadding(substr($str, 1, strlen($str)), $strRemove); } else { printf("returning ===> '$str'<br>"); return "$str"; } }
I wrote the following code, which is in a file test.php, simply to tests the method.
PHP Code:
$num = "000000012"; $pad = 0; $string = removeLeftPadding($num, $pad); printf("Number is $num and remove $pad ====> result '" . $string . "'<br>");
The result of the above code is returning ===> '12'
Number is 000000012 and remove 0 ====> result ''
I played around with the single-quotes and double-quotes, but to no avail. What am I doing wrong? Any help is greatly appreciated.
Thank you,
Bassam
|