Reply to Re: delimited by different characters?

Your name:

Reply:


Posted by Philip Ronan on 10/25/05 16:14

"Dummy Newgroup name" wrote:

> I'm pulling chunks out of a line of text. In this instance the bit I
> want is delimited by square braces; '[' and ']'.
>
> Is there a single php function that I can do this with?
>
> I know how to do it with multiple functions (something like
> substr($string, strpos($string, '['), strpos($string, ']'))(yes, I
> know that's not completely correct), but php seems so rich in its
> string functions I wondered if there's a single function that will do
> it.

Of course there is: <http://php.net/preg_match>

Try this for example (you might need to debug it first):

<?php
$string = "this [foo] is [bar] a [baz] test";
$re = '/\[([^\]]+)\]/';
preg_match($re, $string, $matches);
print_r($matches);
?>


--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

[Back to original 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

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