|
Posted by Bent Stigsen on 06/22/06 20:07
Andy Hassall wrote:
> On 22 Jun 2006 09:24:04 -0700, "frizzle" <phpfrizzle@gmail.com> wrote:
>
>>I have a string, comma separated, with links and their respective URLs
>>in it. Example:
>>Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org
>>
>>etc, etc.
Ooh, seems to be "comma separated string" week.
[snipped non-regex code :)]
> There are undoubtably faster, more concise and cleverer ways of doing
> this.
Rik and Andy J. proved regular expressions was faster and says it is the
clever thing to do. But I am not sure about concise.
$string
= "Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org";
function mickey($minnie, $goofy=null) {
static $pluto = array();
if ($goofy) return $pluto;
$pluto[] = array('name'=>$minnie[1],'url'=>$minnie[2]);
return $goofy;
}
preg_replace_callback('/([^,]*),([^,]*),?/','mickey',$string);
$array = mickey('loves','minnie');
print_r($array);
--
/Bent
[Back to original message]
|