FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » replacing spaces with newline
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: replacing spaces with newline [message #181310 is a reply to message #181307] Sat, 04 May 2013 12:20 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: take two - fetch items from a row.
Next Topic: Unique array of arrays - how can I do this?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 20:36:02 GMT 2024

Total time taken to generate the page: 0.05971 seconds