Page 1 of 1

Help Manipulating String...

Posted: Sat Nov 26, 2005 10:30 am
by pido
I have problem manipulating a string...

Code: Select all

$str = "SLM-03";
$idTemp = str_replace("SLM-","",$str);  // Replace the 'SLM-' with '' and got $idTemp = '03'
intval('$idTemp'); // Change the '03' to integer
$salesID = $idTemp + 1; // Adding the '03' with 1
echo "SLM-$salesID"; // it give me SLM-3 not SLM-03
Question is how do i make print out to SLM-03??? bcuz intval() made my 03 to 3, any idea how to do it right???
Thnx...

Posted: Sat Nov 26, 2005 11:53 am
by foobar

Code: Select all

$str = "SLM-03";
$idTemp = str_replace("SLM-","",$str);  // Replace the 'SLM-' with '' and got $idTemp = '03'
intval('$idTemp'); // Change the '03' to integer
$salesID = $idTemp + 1; // Adding the '03' with 1

#start: magic;
str_pad($salesID, 2, '0', STR_PAD_LEFT);
#end: magic;

echo "SLM-$salesID"; // it give me SLM-3 not SLM-03
:wink:


Let's see if he figures out the comments I made....teehee...

Posted: Sat Nov 26, 2005 7:43 pm
by pido
SO BRILIANT foobar!!! :D Thank you so much...!!!!

but i have to put it in variable first to produce '03'

Code: Select all

$salesID = str_pad($salesID, 2, '0', STR_PAD_LEFT);
This forum is GREAT!!! :lol: