Re: Re: Regular Expression Backreference in subpattern.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/27/08, Nathan Rixham <nrixham@xxxxxxxxx> 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?
> >
> >
>
>
>  $string = '<td>charge</td><td>100</td>';
>  preg_match('|<td>(.*)</td><td>(\d+)</td>|', $string ,
> $out);
>  print_r( $out );

You didnt get my point,.
your codes output will be
Array (2) {
[0] => "charge",
[1]=> "100"
}

But I want this,
Array (1) {
"charge" => 100
}

Thats why I used ?P<name> syntax, In name I used \1, means the last
matched patter would be the key.

I can do this by preg_match_all(), then array_combine() funciton.
But I was thinking if I could make it with calling only preg_match_all
-- 
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux