You are here: Re: split()? « PHP « IT news, forums, messages
Re: split()?

Posted by Matthew Weier O'Phinney on 06/15/05 04:53

* pineriver@vmist.net <pineriver@vmist.net>:
> How would I do this ?
>
> Take this string and return everything between [ ] as an array output doesnt
> have to inlude [ ]
> $rr="thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd";
>
> $a = some function
>
> echo '<pre>';
> print_r($a);
>
> [0] => [ OUT1 ]
> [1] => [ OUT2 ]
> [2] => [ OUT3 ]

preg_match_all('/\[(.*?)\]/', $rr, $a);

This will throw all the matches into $a. $a[0] will be an array that
includes the full string matched for each (which will include the
braces); $a[1] will be an array with just the portions captured (no
braces):

Array
(
[0] => Array
(
[0] => [ OUT1 ]
[1] => [ OUT2 ]
[2] => [ OUT3 ]
)

[1] => Array
(
[0] => OUT1
[1] => OUT2
[2] => OUT3
)

)

--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org

 

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

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