Re: PHP Getting Variables from String
| From: | speedboy | Date: | Tue, 30 Oct 2001 04:55:26 +0000 |
| Subject: | Re: PHP Getting Variables from String | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72835@lists.php.net to get a copy of this message | ||
> $string="These are some words"
>
> I want it to turn into $var1=These, $var2=are, $var3=some, $var4=some
$search_entities = explode(" ", $string);
if (count($search_entities) > 0) {
$criteria = "";
for ($i = 0; $i < count($search_entities); $i++) {
if ($i == (count($search_entities) - 1)) {
$criteria .= "name = '$search_entities[$i]'";
} else {
$criteria .= " name = '$search_entities[$i]' OR ";
}
}
}
$query = "select name from countries where $criteria";
I don't like this though, anyone have a better solution?