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

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
trantron
Forum Newbie
Posts: 5
Joined: Thu Feb 12, 2004 10:36 am

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

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
trantron
Forum Newbie
Posts: 5
Joined: Thu Feb 12, 2004 10:36 am

Post 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' )";
Post Reply