finding and replacing strings in database

Discussion in 'PHP' started by gilgalbiblewheel, Jul 15, 2008.

  1. #1
    I'm trying to find which function fits the script. My objective is to find all the records where there are   including the misspellings (nbsp;, nbsp, &nbsp) and replace them with the space bar " ":
    $sql = "SELECT * FROM ".$acronym."_pages WHERE content LIKE '%nbsp%'";
    $result = mysql_query($sql) OR exit( 'Error: ' . mysql_error() );
    	//echo $sql;
    	function nbspSearch(){
    		//insert code here
    	}
    	while($row = mysql_fetch_array($result)){
    		sql2 = "UPDATE ".$acronym."_pages SET content = '".str_replace(nbspSearch(), " ", $row['content'])."' WHERE content = '".$row['content']."'";
    	}
    mysql_close($con);
    PHP:
    If anyone has a better suggestion than mine let me know. Thanks.
     
    gilgalbiblewheel, Jul 15, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    mwasif, Jul 16, 2008 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    At the moment I got things working but thanks for the info. I need to study php and mySQL in depth! There's no end to studying!
     
    gilgalbiblewheel, Jul 16, 2008 IP
  4. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    $rep=array(' ','&nbsp','nbsp;','nbsp');
    $new=str_replace($rep,' ',$row['content']);

    end then mysql update.
     
    sastro, Jul 16, 2008 IP