Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP how to send carraige returns in a form 3

Status
Not open for further replies.

natwod

Programmer
Nov 21, 2002
41
US
I am trying to send a carraige return (from a text box) to a script. I was able to get the effect I wanted in ASP using the code:

<%
Message = Trim(Request.Form(&quot;message&quot;))
Message = Replace(Message, vbcrlf, &quot;<br>&quot; & vbcrlf)
%>

What this does is replace vbcrlf (the &quot;return&quot; code) with the break tag, as well as vbcrlf. When (return) is pressed, the vbcrlf makes a carraige return in the code sent to the browser, but not in the page displayed.

For PHP, I tried to use the code:

<?php $message = $_POST[&quot;message&quot;]; ?>
<?php echo ereg_replace (&quot;vbcrlf&quot;, &quot;<br>&quot;, $message); ?>

But there were no replacements made.

Does anybody know how to replace the (enter) code with a (br) tag??

Thanks for any input!
Natwod
 
Not 100% positive of what solution you need... but the problem is in the fact that vbcrlf is the VB carriage line feed, not an actually carriage return or line feed or newline.

What you're probably going to need is a (and use this function instead of ereg, it's a tad bit faster...

string_replace(chr(10), &quot;<br>&quot;, $message);
string_replace(chr(13), &quot;<br>&quot;, $message);

that'll get both linefeeds and carriage returns... one or the other is what you need... but both won't hurt... alternatively you could use

string_replace(&quot;\n&quot;, &quot;<br>&quot;, $message);
string_replace(&quot;\r&quot;, &quot;<br>&quot;, $message);

If you're not in the mood to use the ascii codes.

-Rob
 
Note that skiflyer's solution would generate two [tt]<br>[/tt]s per line if the text is coming from a Windows computer (probably from Mac and *NIX too). //Daniel
 
Yeah, I found that out. Thanks! ;)
Natwod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top