Re: Re: Regular Expression Backreference in subpattern.
| From: | Shiplu | Date: | Sat, 27 Sep 2008 22:24:31 +0000 |
| Subject: | Re: Re: Regular Expression Backreference in subpattern. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281058@lists.php.net to get a copy of this message | ||
On 9/27/08, Nathan Rixham <nrixham@gmail.com> wrote:
> Shiplu wrote:
>
> > The string is "<td>charge</td><td>100</td>".
> > I want and array( "charge"=>100).
> > I am using this regular expression,
> > '/<td>([^<]+)<\/td><td>(?P<\1>\d+)<\/td>/'.
> >
> >
> > But its not working..
> >
> > I get this error.,
> > PHP Warning: preg_match(): Compilation failed: syntax error after (?P
> > at offset 25 in E:\src\php\WebEngine\- on line 4
> >
> > any idea?
> >
> >
>
> it seem's everybody is giving you the same answers; here's a definitive
> look at the problem (as far as I'm aware)
>
> all preg_* functions can only return back string's, or array's of strings;
> there is no method of returning back an associative array as you would like;
you can return an array which has friendly name. run the following code,
$x = "a b;c d;e f;";
preg_match('/(?P<keys>\w) (<?P<values>\w)/',$x,$m);
print_r($m);
allso run this code too for backreference idea,
$y = 'a a;b c;d d;e f;f g;h i';
preg_match_all('/(\w) (\1)/',$y,$m);
print_r($m);
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu
Stop Top Posting.