Page 1 of 1

Multi-line string?

Posted: Mon Oct 28, 2002 9:25 pm
by mako1200
Quick question..

I'm trying to format an email body in PHP with variables. But the here document method I'm using is not working. Bascially I want an output similar to this:

Name: $name
email: $email
...
...

Yet, I can't get the carriage returns to output properly. What's the best way to do this? I keep getting parse errors with the here document method..

Any ideas?

Thanks!

Posted: Mon Oct 28, 2002 9:54 pm
by hob_goblin

Code: Select all

$string = "something
something
something";

$string = "something\nsomething\nsomething";
pick your poison

Text Box Formatting...

Posted: Mon Oct 28, 2002 10:42 pm
by rlogin
I have a related question.

In HTML normally we have a text box only. In thetext box, the user may be typing with indents, line breaks etc.

How can they be captured and stored.
I need to do this and then display them.

As an analogy, in this post i left a line gap, how can this be captured?

Also, if i want to give the user the option of formatting like, bold, italics etc. How can i do it?

Any pointers soembody can gice?

Posted: Mon Oct 28, 2002 10:42 pm
by mydimension
or you can do the perl method:

Code: Select all

print <<<END
something
something
something
END;
just make sure that end or whatever you decide to use starts at the beginning of its own line.

Posted: Mon Oct 28, 2002 10:45 pm
by mydimension
rlogin: the quickest way to do this is to use nl2br($someText). this replaces al "\n" with "<br />\n". in general this will always work, although some people need more power and create their own functions. 8)

Posted: Tue Oct 29, 2002 1:37 am
by Takuma

Code: Select all

&lt;?php
str_replace("\n","",$data);
?&gt;

Posted: Tue Oct 29, 2002 2:47 am
by twigletmac
Takuma wrote:

Code: Select all

&lt;?php
str_replace("\n","",$data);
?&gt;
Who wanted a function to remove linebreaks?

Mac

Re: Text Box Formatting...

Posted: Tue Oct 29, 2002 2:52 am
by twigletmac
rlogin wrote:In thetext box, the user may be typing with indents, line breaks etc.

How can they be captured and stored.
I need to do this and then display them.
This kind of formatting will automatically be stored as linebreaks (\n) or tabs (\t) and if you want them to display as entered you can put it within <pre> tags.

Code: Select all

<pre>
    any s    p    a     c     e     s and
line


breaks will be displayed</pre>
rlogin wrote:Also, if i want to give the user the option of formatting like, bold, italics etc. How can i do it?
Allow them to use HTML or have something like the BBCode that this forum uses.

Mac