Jump to content

how can i replace a double space with a single one


shadiadiph

Recommended Posts

<?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";

?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 6 months later...

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.