[newb] preg_replace for an email string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • luke

    [newb] preg_replace for an email string


    hi,

    while i'm not new to php, i'm new to pattern matching and am finding it
    rather difficult .. i would like to take a string that's an email address,
    and change the '@' with '(at)' and any '.'s with '(dot)'. so for instance,
    email@nospam.co m.au would become email(at)nospam (dot)com(dot)au .

    many thanks for any pointers
    luke



  • Micha³ Wo¼niak

    #2
    Re: [newb] preg_replace for an email string

    One quick glance of an experienced eye allowed to understand the blurred
    and almost unreadable luke's handwriting:
    [color=blue]
    >
    > hi,
    >
    > while i'm not new to php, i'm new to pattern matching and am finding it
    > rather difficult .. i would like to take a string that's an email
    > address, and change the '@' with '(at)' and any '.'s with '(dot)'. so
    > for instance, email@nospam.co m.au would become
    > email(at)nospam (dot)com(dot)au .
    >
    > many thanks for any pointers
    > luke[/color]

    Why use preg_replace? It's like firing a cannon on a mosquito. I'd
    recommend str_replace - refer to www.php.net for documentation. It will
    do exactly what you need.

    Cheers
    Mike

    Comment

    • luke

      #3
      Re: [newb] preg_replace for an email string



      "Micha³ Wo¼niak" <mikiwoz_remove _this@yahoo_rem ove_this.co.uk> wrote in
      message news:d4kn37$5q0 $1@213-238-73-81.adsl.inetia. pl...[color=blue]
      > One quick glance of an experienced eye allowed to understand the blurred
      > and almost unreadable luke's handwriting:
      >[/color]

      i like to keep my helpers on their toes.

      thanks for the tip.



      Comment

      • spampop.10.zmalltalker@spamgourmet.com

        #4
        Re: preg_replace for an email string

        preg_replace(ar ray("/@/","/\./"),array("(at)" ,"(dot)"),"firs t.last@host.dom ain.tld");

        Have fun!

        Marius

        Comment

        • luke

          #5
          Re: preg_replace for an email string


          ooh. now that's what i was looking for. many thanks marius!




          "spampop.10.zma lltalker@spamgo urmet.com" <marius.mathies en@gmail.com> wrote
          in message news:1114511956 .918311.266300@ z14g2000cwz.goo glegroups.com.. .[color=blue]
          >[/color]
          preg_replace(ar ray("/@/","/\./"),array("(at)" ,"(dot)"),"firs t.last@host.dom a
          in.tld");[color=blue]
          >
          > Have fun!
          >
          > Marius
          >[/color]


          Comment

          • hackajar@gmail.com

            #6
            Re: preg_replace for an email string

            And to get back to the "cannon on a mosquito" claim

            $email = "noSPAM@example .org";
            $old = array("@", ".");
            $new = array("(at)", "(dot)');

            str_replace($ol d, $new, $email);

            Comment

            Working...