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

?>

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

?>

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

?>

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

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?

  • 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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.