Check variable if explode-able in PHP

Posted by ZaneDeFazio on Stack Overflow See other posts from Stack Overflow or by ZaneDeFazio
Published on 2010-06-17T07:07:38Z Indexed on 2010/06/17 7:13 UTC
Read the original article Hit count: 236

Filed under:

Not sure if there is a way to check a variable if it is explode-able or not...

I have a database of city names some are one word cities and some are multiple word cities

EX: Chicago, Los Angeles

I keep getting an error when use "implode" when a city name is one word, so I tried using "count" and using an if statement... not having any luck

$citi = explode(' ', $row['city']);
$count = count($citi);
if ($count > 1) {
   $city = implode('+', $citi);
}
else {
   $city = $citi;
}

© Stack Overflow or respective owner

Related posts about php