You are here: Re: single array to multidimensional « PHP Programming Language « IT news, forums, messages
Re: single array to multidimensional

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация