Help Manipulating String...

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
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Help Manipulating String...

Post 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...
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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...
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post 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:
Post Reply