Replace all string

Discussion in 'PHP' started by SharingEngines, Feb 27, 2011.

  1. #1
    Hi,

    I have this code he replace a word in a string

    Ex: "http://www.xxx.com" the result are "xxx"
    Ex: "try for sex" the result are "try for"

    But I need to replace all string containing that word.

    Ex: "http://www.xxx.com" the result are ""
    Ex: "try for sex" the result are ""

    $placeholder = array('http', '//', ':', 'sex', 'index.php', '#', '£', 'https', '.com','www.','www','/');
    $replacement = array('');
    	
    $display = str_replace($placeholder, $replacement, $_GET['q']);
    
    mysql_query("INSERT INTO sh SET tags='$display'") or die(mysql_error()); 
    Code (markup):
    Could you help me please?

    Thank you
     
    SharingEngines, Feb 27, 2011 IP
  2. xtmx

    xtmx Active Member

    Messages:
    359
    Likes Received:
    12
    Best Answers:
    4
    Trophy Points:
    88
    #2
    $placeholder = array('http', '//', ':', 'sex', 'index.php', '#', '£', 'https', '.com','www.','www','/');
    $replacement = '';
    	
    $display = str_replace($placeholder, $replacement, $_GET['q']);
    
    mysql_query("INSERT INTO sh SET tags='$display'") or die(mysql_error()); 
    Code (markup):
    Enjoy!
     
    xtmx, Feb 27, 2011 IP