RE: [PHP] a regular expression problem - split text
| From: | John W. Holmes | Date: | Tue, 21 Jan 2003 01:45:44 +0000 |
| Subject: | RE: [PHP] a regular expression problem - split text | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132331@lists.php.net to get a copy of this message | ||
> I have a text like this:
>
> $text=" <!-- 1 --> this is January <!-- 2 --> this is February <!-- 3
-->
> this is March <!-- 4 --> this is April ";
>
> OK.. i want to show e.g. "this is January" in my var $sub_text.
>
> How can i doing this using a regular expressions?
This seems to work.
preg_match_all("/<!-- [0-9]+ -->([a-z ]+)/i",$text,$matches);
$matches will be an array with the values your after in it. Do a
print_r() on it to see how it's structured.
Or, if you're text is always like that, you could just match what's
between the > and < characters, too.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/