#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    I've never seen a reference to this, so I thought I'd ask.

    Does PHP support Class Shorthands, as used by Perl.. such as the d which is the equivilent to a REGEX [0-9], match.

    to give a more thurough example, in Perl, if I wanted to match a phone number I might write my code as follows:

    if ($phone =~ /^((d{3}))? *d{3}-d{4},?*)+$/) {
    do this....
    }

    This would match a typical phone number like (417) 555-1212

    Does PHP also suppor this type of Regex object??

    Or do we have to write them in Long Form.

    In short I'm trying to write a quick regex replace.. which replaces number with "*".. like we often see done with credit card numbers...

    etc.. granted a regex is probably the best solution, but if I can use short hand, it will certainly make it go much faster.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    sure, just use preg_replace() ... 'p' for Perl [style]
  4. #3
  5. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by RyanP:
    sure, just use preg_replace() ... 'p' for Perl [style][/quote]

    Perhaps I've done something wrong, but PHP returned this error...

    Warning: Delimiter must not be alphanumeric or backslash in test.php on line 30

    here's the line of code:
    echo preg_replace("d{4}","*",$card_num1);




    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  6. #4
  7. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Robert_J_Sherman:
    Perhaps I've done something wrong, but PHP returned this error...

    Warning: Delimiter must not be alphanumeric or backslash in test.php on line 30

    here's the line of code:
    echo preg_replace("d{4}","*",$card_num1);


    [/quote]

    Oops, never mind, forgot my "/" in there to set the expression.. duh!

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 10:45 PM
  2. compiled php to support sockets
    By NCAnnie in forum PHP Development
    Replies: 3
    Last Post: February 16th, 2004, 03:44 AM
  3. php support web server
    By poppy_123 in forum PHP Development
    Replies: 12
    Last Post: February 15th, 2004, 10:26 PM
  4. Codepupil
    By Adachic in forum C Programming
    Replies: 3
    Last Post: February 6th, 2004, 06:50 PM
  5. Debian GNU/Linux installation help (Warning: Long post)
    By MasterChief in forum Linux Help
    Replies: 3
    Last Post: January 19th, 2004, 12:28 PM

IMN logo majestic logo threadwatch logo seochat tools logo