...

View Full Version : how do i use an explode on more than one character?



LJackson
02-06-2010, 09:23 PM
Hi,

i have several strings some have a + in it and some have a - in it and some have a ( or ) in it

so what i want to try and achieve is to split the string if either of those characters are found

so i tried this

$string_array = array("Photo Scanner","Film Scanner","ScanJet Scanner","Flatbed Scanner");
$match = false;
foreach($string_array as $v)
{
if(preg_match('/'.preg_quote($v).'/i', $prodName))
{
$temp = $v;
$short_title = preg_replace("/$temp/i", "", $prodName);
$short_title = explode(" - ", $short_title);
$short_title[0] = explode(" + ", $short_title[0]);
$short_title[0] = explode("(", $short_title[0]);
$short_title = trim($short_title[0]);
break;
}
else
{
$short_title = $prodName;
}


but this does not work. if i only use one of the explodes then it works fine, is there a way to get this to work or is there an alternative function i could use?

many thanks
Luke

JAY6390
02-06-2010, 09:57 PM
If you use preg_split() (http://www.php.net/preg_split) with /[+()-]/ as the pattern that should do it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum