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;
}

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.(.*)./

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.