Makke_ Posted April 12, 2013 Share Posted April 12, 2013 I use following code to retrieve data from a database and trim it in different ways to make it look better. and remove unwanted characters and also to be able to use some characters.Allthough in rc_comment string I would also like to remove if possible a specific sentence Created page with or in worst case the three words.I have tried to add $newString = str_replace("Created", " ", $newString); to remove the word Created but this doesnt work.Any idea how to solve this? echo '<table border=0><thead><tr><th></th></tr></thead><tbody>'; $q = mysql_query("SELECT rc_id, rc_title, rc_comment, rc_minor FROM recentchanges WHERE rc_minor = '0' ORDER BY rc_id desc limit 20"); while($f = mysql_fetch_array($q)) { $string = $f['rc_comment']; $newString = $string; $newString = str_replace("/* ", "", $newString); $newString = str_replace(" ", "_", $newString); $newString = str_replace("(", ".28", $newString); $newString = str_replace(")", ".29", $newString); $newString = str_replace(",", ".2C", $newString); $newString = str_replace("&", ".26", $newString); $newString = str_replace("å", ".C3.A5", $newString); $newString = str_replace("ä", ".C3.A4", $newString); $newString = str_replace("ö", ".C3.B6", $newString); echo '<tr><td><span style="color:grey">■    </span><a href="index.php/'.$f['rc_title'].'#'.substr_replace($newString ,"",-4).'" target="_parent">'.$f['rc_title'].' - '.trim($f['rc_comment'], "/* ").'</a></td></tr>'; } echo '</tbody></table>'; Quote Link to comment Share on other sites More sharing options...
Makke_ Posted April 12, 2013 Author Share Posted April 12, 2013 I know noticed I did some mistake.I use following to trim the string. trim($f['rc_comment'], "/* ")I would like to also remove the words Created page with from the same string. Quote Link to comment Share on other sites More sharing options...
Makke_ Posted April 19, 2013 Author Share Posted April 19, 2013 No one? Quote Link to comment Share on other sites More sharing options...
EffakT Posted April 20, 2013 Share Posted April 20, 2013 I tested it and this should work? $newString = $string; $newString = str_replace("/* ", "", $newString); $newString = str_replace(" ", "_", $newString); $newString = str_replace("(", ".28", $newString); $newString = str_replace(")", ".29", $newString); $newString = str_replace(",", ".2C", $newString); $newString = str_replace("&", ".26", $newString); $newString = str_replace("å", ".C3.A5", $newString); $newString = str_replace("ä", ".C3.A4", $newString); $newString = str_replace("ö", ".C3.B6", $newString); $newString = str_replace("Created", " ", $newString); $newString = str_replace("page", " ", $newString); $newString = str_replace("with", " ", $newString); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.