Page 1 of 1

no ending delimeter

Posted: Thu Sep 07, 2006 5:12 am
by mlecho

Code: Select all

$range=range(1,31);
foreach($range as $day){ 
	if($selected=$_GET["Day_$day"]){
		$dv.=$selected."+";
	}
}
$dayVal=preg_split("+",$dv);
foreach($dayVal as $dayNum){
	$update="UPDATE $tableName SET Day_$dayNum='1' WHERE leaderName='".$leader."'";
	mysql_query($update);
}
i know that is probably a bit ugly, but it was working. i am passing some variables from a calendar...Depending on which days are selected, i need to capture those variables. Thus, i put them all into $dv, and add a + sign as a delimeter. Then i extract the values with preg_split, looking for the + between values. It works, kind of....After it executes, i get this warning:

Code: Select all

Warning: preg_split() [function.preg-split]: No ending delimiter '+' found in C:\wamp\www\LeaderRes_May\HTML\uploadInfo.php on line 25

Warning: Invalid argument supplied for foreach() in C:\wamp\www\LeaderRes_May\HTML\uploadInfo.php on line 26
however, below the warning, the output is what i want, and the variables passed...any ideas?

Posted: Thu Sep 07, 2006 6:05 am
by CoderGoblin
+ is a reserved character when pattern matching, similar to [].*?^ etc. Along with '? which 0 or one, * meaning 0 or more, + means 1 or more.

To use it you should escape it

Code: Select all

$dayVal=preg_split("\+",$dv);
At the moment it works on an assumption/side-effect.

Posted: Thu Sep 07, 2006 7:18 am
by Mordred
Not only escape it, but put some preg delimiters as well! I like to use tildes:

Code: Select all

'~\+~'

Posted: Thu Sep 07, 2006 7:22 am
by mlecho
of all the delimeters i could pick! Thanks guys.