SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Location
    Minneapolis, MN, USA
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey peoples! I was wondering if there is a function in PHP similar to Perl's "s///". s/// searches for a term and replaces it with the other term (s/search/replace/). So...if there is...it'd be really awesome.

    Thanks alot!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean regular expressions.

    ereg_replace("strtoreplace", "strtoreplacewith", "strtoreplacein");

    Or the case insensitve version eregi_replace()

    or for a faster method if you don't need all the regular expression stuff

    str_replace()

    and stri_replace()
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Location
    Minneapolis, MN, USA
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot!

  4. #4
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    preg_replace() is faster than ereg_replace() ..

    preg_replace() will let you use perl style regular expressions...

    cogito, ergo sum

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    str_replace is faster than both provided you don't need the added functionality of regular expressions
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been using str_replace a lot but have often found I need a previous str_replace to convert from Upper to Lower case (or vice versa), so as to make sure everything I want is always replaced.

    Is stri_replace a case insensitive version that would solve this? I've never come across it.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There I go opening my mouth again, it seems there is no stri_replace and I just made it up. You could probably combine the function to make it work for you though, maybe

    $str = strtololower(str_replace($strtoreplace, $strtoreplacewith, $strtoreplacein));

    For example
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •