no ending delimeter

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
mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

no ending delimeter

Post 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?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

Not only escape it, but put some preg delimiters as well! I like to use tildes:

Code: Select all

'~\+~'
mlecho
Forum Commoner
Posts: 53
Joined: Wed Feb 02, 2005 9:59 am

Post by mlecho »

of all the delimeters i could pick! Thanks guys.
Post Reply