SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Replace text

  1. #1
    Non-Member bigrollerdave's Avatar
    Join Date
    Mar 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace text

    How would I go about replacing something with someting else? I know I can use str_replace, but I have a problem with that. Say I block the word test if someone types Test then It wont be blocked anymore because it's case sensitive. How can I get around doing that?

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What version of PHP are you using?

    PHP5 has a case insensitive str_replace function called str_ireplace.

  3. #3
    Non-Member bigrollerdave's Avatar
    Join Date
    Mar 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    4.3.11

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    note on php.net by Harry Fuecks (Sitepoint uberdude)
    hfuecks at nospam dot org
    04-Jul-2005 10:07
    Note that character case is being defined by your server's locale setting, which effects strings containing non-ASCII characters.

    See strtolower() - http://www.php.net/strtolower and comments - internally str_ireplace converts $search and $replace to lowercase to find matches.
    Might be of use

    Spike

  5. #5
    Non-Member bigrollerdave's Avatar
    Join Date
    Mar 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    note on php.net by Harry Fuecks (Sitepoint uberdude)

    Might be of use

    Spike
    Yeah, I thought about usign that method, but wouldn't the string be all lowercase? I don't want to convert everything to lowercase.


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
  •