shadiadiph Posted March 20, 2009 Share Posted March 20, 2009 how can i replace a double space with a single one? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 <?php $word="hello i am reddarrow"; $test=str_replace(" "," ",$word); echo $test; ?> tested <?php $word="hello i am reddarrow"; $test=str_replace(" "," ",$word); echo $test; echo "<br><br>The name word is ".strlen($word)." charecters <br> The name $test is ".strlen($test)." charecters"; ?> Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted March 20, 2009 Author Share Posted March 20, 2009 mm doesn't seem to work every instance of a double space is after a " for eample. house" said street" was Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 proper way then!. <?php $word="hello i am reddarrow"; $test=str_replace(" "," ",$word); echo $test; echo "<br><br>The name word is ".strlen($word)." charecters <br> The name $test is ".strlen($test)." charecters"; ?> Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted March 20, 2009 Author Share Posted March 20, 2009 mm doesn't seem to work don't know why Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 my last attempt sorry. <?php $word=" hello i am reddarrow"; $test=preg_replace("/ /"," ",$word); echo $test; echo "<br><br>The name word is ".strlen($word)." charecters <br> The name $test is ".strlen($test)." charecters"; ?> Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted March 20, 2009 Author Share Posted March 20, 2009 mm dont know why but the spaces i was mentioning are showing as � when called from the database how can I replace these? they were showing as blank spaces before i added the article to the database and couln't replace them with str_ replace i saved the article to the database using $article = stripslashes($article); $article = nl2br($article); $article = mysql_real_escape_string($article); Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 can you give a link to see what you are doing? this should have been good <?php $word="hello i am reddarrow"; $test=str_replace(" "," ",$word); echo $test; ?> Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted March 20, 2009 Author Share Posted March 20, 2009 mm this seems to be the problem when i use. $pattern4 = '/’â€/'; $replacement4 = '"'; $article = preg_replace($pattern4, $replacement4, $string4); it is replacing the symbol with '"' the two hypens around the quote also? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 need a diff regex, not sure what though. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted March 20, 2009 Author Share Posted March 20, 2009 all the whitespaces appear after ’†and †i have just spent hours playing with it and got nowhere i can remove those charachters fine but the whitespace after them just can't get rid of it Quote Link to comment Share on other sites More sharing options...
NWCAthletics.com Posted September 30, 2009 Share Posted September 30, 2009 Did anybody find a resolution to this issue? I am having a similar problem. I am pulling posts from a WordPress database and everywhere that there is a double space, a box and a space is displayed. When I look at the record in the database, I see two spaces. When I try to replace two spaces with a single space using str_replace or preg_replace, it doesn't find two spaces and ignores the command. $post_text = "Why doesn't this work? It is driving me nuts!"; $post_text = str_replace(" ", " ", $post_text); echo($post_text); Why doesn't this work? It is driving me nuts! Virtual beer for whoever figures this out! Quote Link to comment Share on other sites More sharing options...
daydreamer Posted September 30, 2009 Share Posted September 30, 2009 <?php $word="hello i am reddarrow"; $test=preg_replace("~[\s]{2}?[\t]?~i"," ",$word); echo $test; ?> This works for me. Let me know about that virtual beer, Quote Link to comment Share on other sites More sharing options...
NWCAthletics.com Posted September 30, 2009 Share Posted September 30, 2009 Nice try but all that seems to do is produce an empty string. Here's an example of the problem output... Do a find on "TV" and you'll see a box right after it. You'll also see this repeated numrous times throughout the article whereever the author used a double-space. http://www.nwcathletics.com/index.php?act=view_post&league=1&page_name=team_news&post_id=687&school=0&sport=1&tab=1 Quote Link to comment Share on other sites More sharing options...
NWCAthletics.com Posted September 30, 2009 Share Posted September 30, 2009 Well, looks like I get to buy myself a beer. The mysterious character is #160. Not sure how it gets in there but if I replace it with an empty string, all is well. $text = str_replace(chr(160),"",$text); 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.