Page 1 of 1

array + str_replace issues :(

Posted: Sat May 08, 2010 5:17 pm
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 :(

Re: array + str_replace issues :(

Posted: Sat May 08, 2010 6:49 pm
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.

Re: array + str_replace issues :(

Posted: Sat May 08, 2010 8:03 pm
by Torniquet
chris you are a genious

i can remove the poxy if statements now :D

^^