Jump to content

preg_match - Delimiter must not be alphanumeric or backslash


redbrad0

Recommended Posts

I am working on taking out the Deprecated functions from my site so while replacing ereg with preg_match I get the below error. Per a message I found on the internet it says to replace ereg with preg_match and everything should work. Can anyone assist me with fixing this error?

 

Error: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

 

Part where error is contained

if (preg_match('enum.(.*).', $row['Type'], $match)) {
    $opts = explode(',', $match[1]);
    foreach ($opts as $item)
        $finalResult[] = substr($item, 1, strlen($item)-2);
}

 

Full Function

function getEnumOptions($table, $field) {
   global $db;
   
   $finalResult = array();

   if (strlen(trim($table)) < 1)
   	return false;
   	
   $query  = "show columns from " . $db['tickets_slave']->escapeSimple($table);
   $res =& $db['tickets']->query($query);
   if (PEAR::isError($res))	{
		throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR);
   }	else	{
		try	{
			while ($res->fetchInto($row))	{
        if ($field != $row["Field"])	{
        
      	}	else	{	        
	        //check if enum type
	        if (preg_match('enum.(.*).', $row['Type'], $match)) {
	            $opts = explode(',', $match[1]);
	            foreach ($opts as $item)
	                $finalResult[] = substr($item, 1, strlen($item)-2);
	        }
      	}
			}
		} catch (TixException $ex) {
			throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR);
		}
   }
   return $finalResult;
}

Link to comment
Share on other sites

ereg and PCRE are very different, even if some things look the same.

 

Difference #1: PCRE needs delimiters around the expression. These don't contribute to the pattern itself. Common delimiters are /.../ and #...# but you can use just about any symbol you want.

/enum.(.*)./

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.