PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 16th, 2004, 12:33 PM
bkhouri80 bkhouri80 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 bkhouri80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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($str01), $strRemove) == 0) && (strlen($str) != 1) )
{
    
removeLeftPadding(substr($str1strlen($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

Reply With Quote
  #2  
Old August 16th, 2004, 02:20 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Why not just use intval() to strip zeroes off the front?
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old August 16th, 2004, 02:56 PM
bkhouri80 bkhouri80 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 bkhouri80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by dhouston
Why not just use intval() to strip zeroes off the front?
It worked!!!! Coolio!!! Thanks a bunch for your help!

Bassam

Reply With Quote
  #4  
Old August 16th, 2004, 07:02 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 956 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 8 h 23 m 34 sec
Reputation Power: 4
Send a message via ICQ to Itsacon
alternatively, when you don't want it converted to an integer, you can use the functions trim(), ltrim() and rtrim() to remove spaces from both sides, left side or right side respectively.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > custom function not returning a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway