Jump to content

Warning: preg_match() [function.preg-match]: No ending delimiter


vicodin

Recommended Posts

Every time i run this function i get a Warning: preg_match() [function.preg-match]: No ending delimiter "|"

No sure what im doing wrong. So what i want to accomplish is if there are any | in the string then take only the first peice of data and forget the rest. If there is no | in the string leave it alone. The script runs but i get a:

Warning: preg_match() [function.preg-match]: No ending delimiter '|' found

function Excludeit($str){
if(preg_match('|',$str)){
$str=substr($str,0,strpos($str,'|'));
}
else
{
$str=$str;
}
}

Any ideas anyone.?

<?php

function Excludeit($str)
{
    $ex = explode("|", $str);
    
    if(count($ex) > 1){
	return $ex[0];
}else {
	return $str;
}
}

echo Excludeit('pie|goat') . "<br>" . Excludeit('lemons');

?>

 

results

pie
lemons

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.