Page 1 of 1

Need help on substr function

Posted: Thu Feb 14, 2008 4:42 pm
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

Re: Need help on substr function

Posted: Thu Feb 14, 2008 4:47 pm
by Benjamin
Is it always a single "A"?

Re: Need help on substr function

Posted: Thu Feb 14, 2008 4:50 pm
by cyberlei
Yes, always start with "A"

Re: Need help on substr function

Posted: Thu Feb 14, 2008 4:52 pm
by Benjamin
Use the ltrim() function.

Re: Need help on substr function

Posted: Thu Feb 14, 2008 7:21 pm
by cyberlei
something like:
#
<?php
#
substr=ltrim($sn,0,A)
#
?>

Re: Need help on substr function

Posted: Thu Feb 14, 2008 7:31 pm
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.

Re: Need help on substr function

Posted: Thu Feb 14, 2008 7:44 pm
by Christopher

Code: Select all

$sn = ltrim($sn,0,'A');
// or 
$sn = substr($sn,1);

Re: Need help on substr function

Posted: Thu Feb 14, 2008 8:01 pm
by Benjamin
I'm pretty sure ltrim only accepts 2 parameters.

Code: Select all

 
$sn = ltrim($sn, 'A');
 

Re: Need help on substr function

Posted: Fri Feb 15, 2008 3:23 pm
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:

Re: Need help on substr function

Posted: Fri Feb 15, 2008 4:43 pm
by RobertGonzalez
For the record, there is a rtrim() and trim function as well, that work pretty much the same way.