Page 1 of 1

string_replace

Posted: Tue Oct 13, 2009 12:14 pm
by lwaddle
Ok... I'm very new with PHP, but am trying to learn. Here's my problem: I have 2 arrays of numbers ($arrweight and $arrmoment). I am receiving $fuel from a form. What I want to do is lookup what is entered in the form ($fuel) in the array $arrweight and replace it with what is in array $arrmoment. Here's what I have so far. It works until $fuel is greater than 900.

$fuel = $_POST['fuel'];

$arrweight = array("100","200","300","400","500","600","700","800","900","1000","1100","1200","1300","1400","1500","1600","1700","1800","1900","2000","2100","2200","2300","2400","2500","2600","2700");
$arrmoment = array("22572","45161","67776","90443","113351","136538","159955","183555","207111","230572","253974","277441","300811","324221","347656","371079","394500","417912","441347","464746","488120","511463","534839","558130","581450","604724","628029");

$newfuel = str_replace($arrweight, $arrmoment, $fuel);
echo $newfuel;

Any ideas? Thanks in advance.

-newbie

Re: string_replace

Posted: Tue Oct 13, 2009 2:47 pm
by desperado
does your text field have a max limit=3 characters on your form?