Page 1 of 1

explode() question Does this work on all versions of PHP ...

Posted: Thu Feb 12, 2004 10:36 am
by trantron
I am running this code on version 4.3.4

This code takes a range of years e.g. 1980-85 and inserts into the database 80,81,82,83,84,85

$yr=explode("-", $years);
if($yr)
{
$left=substr($yr[0],-2);
$right=substr($yr[1],-2);
$var=range("$left","$right");
for($i=0; $i < $right; $i++)
$years=implode(",", $var);

}//end if

I then use the variable $years in a database.

The code works perfect on version 4.3.4 but when I run it on version 4.2.1 it does not work

I only get a singe digit. In this case it would just be an 8

Does anybody know why??

Thanks

Posted: Thu Feb 12, 2004 11:05 am
by JayBird
where is the variable years being set?

You need to show us more of your code. explode() doesn't have any issues with different version, so i am guessing it is another problem with your code.

Mark

Posted: Thu Feb 12, 2004 11:26 am
by trantron
$years is then being sent to a MySQL database.

Here is the rest of the code, this all works on one server but not the other.



$yr=explode("-", $years);
if($yr)
{
$left=substr($yr[0],-2);
$right=substr($yr[1],-2);
$var=range("$left","$right");
for($i=0; $i < $right; $i++)
$years=implode(",", $var);
}//end if



$query="INSERT INTO midway(div, rate, name, years, email, photo, notes, pass, id)VALUES (trim('$div'), trim('$rate'), trim('$name'), trim('$years'), trim('$email'), trim('$photo'),trim('$notes'), trim('$pass'), '$id' )";