SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expression return only string

    Code:
    <?php
    	$string = "igonore this text ORG:my organisation END:VCARD";
    	$regex = '/ORG:([^.]+)/';
    		
    	if (preg_match($regex, $string, $matches))
    		echo $matches[0];
    ?>
    This regular expression returns:
    ORG:my organisation END:VCARD

    How do I get it to return
    "my organisation"
    ...by itself?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    preg_match
    (
        
    '~(?<=ORG:).*?(?=END:VCARD)~i',
        
    'igonore this text ORG:my organisation END:VCARD',
        
    $matches
    );
    echo 
    array_shift($matches); #my organisation 
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant. Thanks very much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •