Re: PHP Getting Variables from String
| From: | brendan | Date: | Tue, 30 Oct 2001 05:00:22 +0000 |
| Subject: | Re: PHP Getting Variables from String | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72839@lists.php.net to get a copy of this message | ||
Use the eval function
$string="word1 word2 word3 word4);
$string_array=explode(" ",$string);
for ($x=0;$x<count($string_array);$x++)
{
eval("\$var".$x."=\"".$string_array[x]."\";");
}
probably needs debugging ...
Speedboy wrote:
$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?