You are here: Re: PREG search for multiple values in one pass? « PHP Programming Language « IT news, forums, messages
Re: PREG search for multiple values in one pass?

Posted by Alvaro G. Vicario on 08/19/06 08:49

*** terence.parker@gmail.com escribió/wrote (18 Aug 2006 18:46:28 -0700):
> I wish to grab the data "This is a title" and "Fred" against their
> corresponding headings in an array (e.g. $array[title] = "This is a
> title") .... but the key doesn't matter, that need not come from the
> regexp but I can do manually.
>
> The question is - how do I do this in one pass?


I'm unsure about your exact needs, but I hope this code helps:


$text='<b>Title:</b> <em>This is a title</em>
<b>Name:</b> <em>Fred</em>';

if(preg_match_all('@<b>(.*)</b>.*<em>(.*)</em>@Ui', $text, $matches)>0){
print_r($matches);
}


This prints:

Array
(
[0] => Array
(
[0] => <b>Title:</b> <em>This is a title</em>
[1] => <b>Name:</b> <em>Fred</em>
)

[1] => Array
(
[0] => Title:
[1] => Name:
)

[2] => Array
(
[0] => This is a title
[1] => Fred
)

)


If keys don't matter, must ignore them: '@<b>.*</b>.*<em>(.*)</em>@Ui'

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

 

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

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