Re: newbie array question
| From: | Rasmus Lerdorf | Date: | Tue, 13 Aug 2002 19:01:30 +0000 |
| Subject: | Re: newbie array question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-112406@lists.php.net to get a copy of this message | ||
Two ways I can think of off the top of my head:
$s = "('item','item2','item3')";
preg_match_all("/'(.*?)'/",$s,$regs);
$result = $regs[1];
or
$s = "('item','item2','item3')";
eval('$result = array'.$s.';');
Neither is very efficient though. eval() is particularly ugly.
-Rasmus
On Tue, 13 Aug 2002, Alexander Ross wrote:
> If I have a string variable that is already of the form
> ('item','item2','item3') [including the parens and quotes in
> the string],
> is there an easy way to change that variable into an array??
> Array($var) doesn't work. Thanks
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>