Re: Re: String /pattern formatting extraction question
| From: | Robin Vickery | Date: | Mon, 10 Apr 2006 14:27:04 +0000 |
| Subject: | Re: Re: String /pattern formatting extraction question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233670@lists.php.net to get a copy of this message | ||
On 10/04/06, Andy <frum@ar-sd.net> wrote:
> >> text1 /ptext2 /otext3
> > Does it always look like that?
> > text1(whitespace)/ptext2(whitespace)/otext3
>
> The ideea is to extract the texts before and between /o and /p.
> $html = "asdäüü ö ö vf /pxtestxx/ostestss";
> eregi("^([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[1]
> eregi("^(.*)/p([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]
> eregi("^(.*)/o([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]
>
> This example works, but I thought there might be a better way to extract the
> texts, with a single ereg or preg_match.
Well... slightly.
preg_match( '#^(+)/p(.+)/o(.+)$#',
preg_replace('#^(.+)(/o.+)(/p.+)$#', '$1$3$2', $html), $reg);
-robin