MyBB Community Forums

Full Version: Help with regex
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
$newleaders = str_replace(",," , $newleaders , ",");

Basically what I want it to do is search the string $newleaders for two consequtive commas and change it to just a single comma.

I originally had this code
if ($groupinfo['additionalleaders']==NULL || $groupinfo['additionalleaders']==",")
			{
				$newleaders = $userid;
			}
			else
			{
				$newleaders = $groupinfo['additionalleaders'] . "," . $userid;
			}
			// Try and make sure it is safe.
			 $newleaders = str_replace(",," , $newleaders , ",");
			if ($newleaders==",")
			{
				$newleaders = "";
			}
But it turned out $newleaders would keep being NULL. :headbang
Looks like you just mixed up the str_replace function actually.

Try this:
$newleaders = str_replace(",,", ",", $newleaders);
I'll test that out tomorrow, thanks.