GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   A Quick PHP Question... (https://gfy.com/showthread.php?t=647244)

Big John 08-22-2006 12:50 PM

A Quick PHP Question...
 
I need to combine some strings and send them to a page with a multi-line form field in it (hope that makes sense). In itself this is simple and so's the problem...

I want to insert a line break betweek each bit of data (it's an address field and I want each piece on its own line). How to do it? Obviously being an form field <br \> won't work so what do I use? Is there an escape character?

for example I want:

$ addressfield = $ street . (new line) . $ city . (newline) etc

I figure someone here must know how to do something so simple. It's such a daft thing to not know how to do that finding how is proving impossible.

Nookster 08-22-2006 12:52 PM

$addressfield = $street . '\n' . $city . '\n' . $etc;

munki 08-22-2006 12:55 PM

I think this is what you are looking for, or at least close.

http://us2.php.net/manual/en/function.nl2br.php

boldy 08-22-2006 12:56 PM

use "\n\r" or "\r"

not sure. :)

Nookster 08-22-2006 12:58 PM

Quote:

Originally Posted by munki
I think this is what you are looking for, or at least close.

http://us2.php.net/manual/en/function.nl2br.php

Actually he's looking to do the opposite. Here's a bit of code I found years ago that does the trick if you need to convert <br> tags to the newline char...
Code:

function br2nl($text) {
  $text = str_replace("<br />","",$text);
  $text = str_replace("<br>","",$text);
  return $text;
}


boldy 08-22-2006 01:01 PM

a newline char is \r in a multiline textfield like textarea .

boldy 08-22-2006 01:02 PM

try this

$addressfield = $street . "\r" . $city . "\r";

Big John 08-22-2006 01:02 PM

\n wasn't working for some odd reason. Hmmm...thanks for the replies. I'll try combining it with r as suggested :)

Big John 08-22-2006 01:08 PM

That did it - \r :)

boldy 08-22-2006 01:09 PM

Quote:

Originally Posted by Big John
That did it - \r :)


You are welcome :thumbsup

Big John 08-22-2006 01:31 PM

Quote:

Originally Posted by boldy
a newline char is \r in a multiline textfield like textarea .


You'd be amazed how hard it is to find that little bit of info. I found quite a few pages listings various escape characters etc that missed out the /r. Oh well - now I know and won;t forget. Thanks again :)


All times are GMT -7. The time now is 06:28 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123