preg_match in php

Discussion in 'PHP' started by komrad, Jul 26, 2008.

  1. #1
    Hi all,

    I'd like to know how can I return the string position in a match with a regular expression (preg_match in php)?
    I would like to return an array including the string position of the match.

    Any help greatly appreciated.

    Thank in advance.
     
    komrad, Jul 26, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    As far as I know, that's not possible. But strpos() and stripos() will do that.
     
    nico_swd, Jul 26, 2008 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    It's possible with PREG_OFFSET_CAPTURE flag:
    RTFM
     
    wmtips, Jul 28, 2008 IP
  4. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    And if you need to get offsets of all occurrences of the string, use preg_match_all().
     
    rohan_shenoy, Jul 28, 2008 IP