FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Dynamic backreferences, finding last in a group
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Dynamic backreferences, finding last in a group [message #179067 is a reply to message #179066] Sun, 09 September 2012 14:16 Go to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma:
Senior Member
On 9/9/2012 4:51 AM, Anders Wegge Keller wrote:
> Jason C <jwcarlton(at)gmail(dot)com> writes:
>
>> Any suggestions?
>
> Read the manual on regexp syntax, and use named patterns.
>

Wow that is a very good feature I never know about.

This I can imagine will come in very handy.

Thanks
Scotty


Example #4 Using named subpattern
<?php

$str = 'foobar: 2008';

preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);

/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however
* the above form is recommended for backwards compatibility */
// preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);

print_r($matches);

?>

The above example will output:

Array
(
[0] => foobar: 2008
[name] => foobar
[1] => foobar
[digit] => 2008
[2] => 2008
)
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Php
Next Topic: Please help In if else while using array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 17:30:05 GMT 2024

Total time taken to generate the page: 0.05387 seconds