SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ereg deprecated problem

    Hello

    anyone can help to convert this

    ereg("^\[?[0-9\.]+\]?$", $val2)

    using preg_match?

    I am trying

    preg_match("/^\[?[0-9\.]+\]?$/", $val2)

    however it does not work in the same way

    thank you
    trcris ::> http://www.trcris.com

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no it works I was wrong , however anyone can tell me difference between

    preg_match("/^\[?[0-9\.]+\]?$/", $val2)

    and

    preg_match("{^\[?[0-9\.]+\]?$}", $val2)


    which seem to work in the same way ?
    trcris ::> http://www.trcris.com

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,036
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Yup, those do the same thing.
    You can choose any character you like for the start and end of the expression, as long you use the same character for both.
    The thing is that the character you choose has to be escaped if you use it in the expression itself, which is why some characters are a poor choice (like / which I find needs to matched quite a lot).
    My personal preference goes to ~ because that almost never occurs in an expression. Of course that is personal, other people might prefer other characters.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Yup, those do the same thing.
    You can choose any character you like for the start and end of the expression, as long you use the same character for both.
    The thing is that the character you choose has to be escaped if you use it in the expression itself, which is why some characters are a poor choice (like / which I find needs to matched quite a lot).
    My personal preference goes to ~ because that almost never occurs in an expression. Of course that is personal, other people might prefer other characters.

    I didn't know it , very useful thank you
    trcris ::> http://www.trcris.com

  5. #5
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by graziano68 View Post
    no it works I was wrong , however anyone can tell me difference between
    The difference is only in the delimiters, for how they should/can be used see http://php.net/regexp.reference.delimiters
    Salathe
    Software Developer and PHP Manual Author.


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
  •