Need help on substr function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cyberlei
Forum Commoner
Posts: 27
Joined: Tue Oct 16, 2007 6:19 pm
Location: Milpitas, CA

Need help on substr function

Post by cyberlei »

Hello Guys,

Just wondering how I can make the substr value changes when submit into mysql.

something like:
someone typed A123456 on a blank field and submit into mysql.the Value will only display 123456 on mysql

Thanks a lot
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help on substr function

Post by Benjamin »

Is it always a single "A"?
cyberlei
Forum Commoner
Posts: 27
Joined: Tue Oct 16, 2007 6:19 pm
Location: Milpitas, CA

Re: Need help on substr function

Post by cyberlei »

Yes, always start with "A"
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help on substr function

Post by Benjamin »

Use the ltrim() function.
cyberlei
Forum Commoner
Posts: 27
Joined: Tue Oct 16, 2007 6:19 pm
Location: Milpitas, CA

Re: Need help on substr function

Post by cyberlei »

something like:
#
<?php
#
substr=ltrim($sn,0,A)
#
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help on substr function

Post by Benjamin »

Without looking at the manual, I'm pretty sure you only need two parameters, the string and the characters to remove. The 0 doesn't need to be there.

EDIT: The A needs to be in quotes.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help on substr function

Post by Christopher »

Code: Select all

$sn = ltrim($sn,0,'A');
// or 
$sn = substr($sn,1);
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help on substr function

Post by Benjamin »

I'm pretty sure ltrim only accepts 2 parameters.

Code: Select all

 
$sn = ltrim($sn, 'A');
 
cyberlei
Forum Commoner
Posts: 27
Joined: Tue Oct 16, 2007 6:19 pm
Location: Milpitas, CA

Re: Need help on substr function

Post by cyberlei »

astions wrote:I'm pretty sure ltrim only accepts 2 parameters.

Code: Select all

 
$sn = ltrim($sn, 'A');
 
Issue Resolved, working perfect, Thanks a lot guys :drunk:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Need help on substr function

Post by RobertGonzalez »

For the record, there is a rtrim() and trim function as well, that work pretty much the same way.
Post Reply