Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    127.0.0.1
    Posts
    67
    Thanks
    19
    Thanked 0 Times in 0 Posts

    str_replace() problem

    hi. I have some string:
    PHP Code:
    $string "PHP is the best!"
    , then I have another string that I get from user:
    PHP Code:
    $_POST['q'] = "php"
    .
    So I found a match. Now I display $string and replace it like this
    PHP Code:
    $string str_replace($_POST['q'], "<b>".$_POST['q']."</b>"$string); 
    .
    So I want to make the searched text bold in the $string. But it works only if $_POST['q'] is "PHP" not if "php" or "Php". Is there any way to fix this?
    Last edited by sonic656; 07-20-2012 at 11:13 PM.
    My website is here: http://www.moowdesign.eu/. It is not complete yet, and I want to add language translations for some languages(including english).

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep, you can use str_ireplace for insensitive searches.
    Regex is also an option as well, although when you know exactly what you are searching for and what you are replacing with then you should use str_replace family.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •