Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #9255
| From | bill <william@TechServSys.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: replacing spaces with newline |
| Date | 2013-05-04 08:20 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <km2udk$9cm$2@speranza.aioe.org> (permalink) |
| References | <6964ae80-5d55-44bf-984e-9277b42fc67d@googlegroups.com> |
On 5/4/2013 7:09 AM, Simon Hall wrote:
> Hi Guys,
>
> I am new to PHP and I am trying to clean up some text,
what I am looking to do is to create a new line at each space,
I have tried the following but it still outputs with just spaces.
>
> <?php
>
> $file = file_get_contents("mytext.txt");
>
> $file = Str_replace(" ", "\r\n", $file);
>
> echo $file;
>
> ?>
>
> Any ideas?
>
>
> Cheers
>
>
> Simon
>
When displaying in a browser multiple spaces/tabs/newlines are
all rendered as 1 space. If you want the _display_ to treat
spaces as newlines use the html line break:
$file = Str_replace(" ", <br />", $file);
or keep what you have and use
$file = nl2br($file)
http://us2.php.net/manual/en/function.nl2br.php
bill
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
replacing spaces with newline Simon Hall <hall.simon82@gmail.com> - 2013-05-04 04:09 -0700 Re: replacing spaces with newline Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-04 12:14 +0000 Re: replacing spaces with newline bill <william@TechServSys.com> - 2013-05-04 08:20 -0400 Re: replacing spaces with newline Jeff North <jnorthau@yahoo.com.au> - 2013-05-04 22:24 +1000 Re: replacing spaces with newline Simon Hall <hall.simon82@gmail.com> - 2013-05-04 07:43 -0700
csiph-web