Multi-line string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mako1200
Forum Newbie
Posts: 1
Joined: Mon Oct 28, 2002 9:25 pm

Multi-line string?

Post 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!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

$string = "something
something
something";

$string = "something\nsomething\nsomething";
pick your poison
rlogin
Forum Newbie
Posts: 19
Joined: Fri Oct 18, 2002 2:39 am

Text Box Formatting...

Post 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?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Code: Select all

&lt;?php
str_replace("\n","",$data);
?&gt;
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Takuma wrote:

Code: Select all

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

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Text Box Formatting...

Post 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
Post Reply