Connecting Tech Pros Worldwide Forums | Help | Site Map

Help removing a simple space

vbMark
Guest
 
Posts: n/a
#1: Sep 20 '05
I need to check for sentences that have a space before the period and
remove the space. I've tried:

$sentence = str_replace(" .", ".", $sentence);

but it does not work. I've tried other ways with no success.

Why doesn't this work and how do I do this?

Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Get freeware
http://www.vbmark.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Steve
Guest
 
Posts: n/a
#2: Sep 20 '05

re: Help removing a simple space


[color=blue]
> $sentence = str_replace(" .", ".", $sentence);
>
> but it does not work. I've tried other ways with no success.[/color]
[color=blue]
> Why doesn't this work and how do I do this?[/color]

Maybe they are not spaces (ASCII 32). Could be some other white-space
characters, like TAB (ASCII 9) or FF (ASCII 12). Remember that viewing
text through a browser compresses runs of white-space down to a single
visual space. Look at the HTML source to be sure, ideally using a text
viewer or hex-editor that can highlight different kinds of white-space.

If that's the case look at regular expression functions eg
<http://www.php.net/preg_replace> for a solution.

---
Steve

vbMark
Guest
 
Posts: n/a
#3: Sep 20 '05

re: Help removing a simple space


"Steve" <googlespam@nastysoft.com> wrote in news:1127231674.590793.44210
@f14g2000cwb.googlegroups.com:
[color=blue]
>[color=green]
>> $sentence = str_replace(" .", ".", $sentence);
>>
>> but it does not work. I've tried other ways with no success.[/color]
>[color=green]
>> Why doesn't this work and how do I do this?[/color]
>
> Maybe they are not spaces (ASCII 32). Could be some other white-space
> characters, like TAB (ASCII 9) or FF (ASCII 12). Remember that viewing
> text through a browser compresses runs of white-space down to a single
> visual space. Look at the HTML source to be sure, ideally using a text
> viewer or hex-editor that can highlight different kinds of white-space.
>
> If that's the case look at regular expression functions eg
> <http://www.php.net/preg_replace> for a solution.
>
> ---
> Steve
>
>[/color]

Ah! That was it. It wasn't a 32, it was a 13 and a 10.

Thanks for your help.

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Get freeware
http://www.vbmark.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Closed Thread