array + str_replace issues :(

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

array + str_replace issues :(

Post by Torniquet »

ok... here is the deal lol.

the code i have is as follows...

Code: Select all

	$orig = array('1','2','3','4','5','6','7','8','9','10','11','12');
	$rep = array('Helmet','Chest','Legs','Boots','Belt','Weapon','Shield','Necklace','Bracelet','Glove','Ring','Relic');
	$equipmentType = str_replace($orig,$rep,$_GET['equipment']);

now when the replace hits 10,11 etc.... it doesnt replace it with the right value,

instead it replaces it with helmet then helmetchest helmetlegs etc..

how the flaming hell do i stop this :(
New Site Coming Soon! Stay tuned :D
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: array + str_replace issues :(

Post by Chris »

The longest numbers will need to go first:

Code: Select all

$orig = array('10','11','12','1','2','3','4','5','6','7','8','9');
 
PHP will replace the values in order, so it will replace '1' first if it's first in the list.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: array + str_replace issues :(

Post by Torniquet »

chris you are a genious

i can remove the poxy if statements now :D

^^
New Site Coming Soon! Stay tuned :D
Post Reply

Return to “Advanced Help and Support”