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)
-   -   quick php question (https://gfy.com/showthread.php?t=1136916)

mkx 03-26-2014 01:42 PM

quick php question
 
I am using the following code to echo a customers address from a mysql database:

<?php print $recipient->address_street ?>

However, in the DB if there are 2 lines in the value, for example:

123 street
Apt 1

and it will echo it like it is in the db with the double lines. How can I make it echo on just one line, preferably with a comma and space:

123 Street, Apt 1

nm_ 03-26-2014 02:23 PM

the address string probably has a newline in it or something

123 street
Apt 1

is probably really something like 123 street\n\rApt 1, so maybe look into using preg_replace to replace \n or \n\r with ", " (maybe str_replace works for this too??).

sorry maybe someone who knows php better will chime in with exact code for you ;]

mkx 03-26-2014 02:27 PM

that sounds like it could work, if anyone can provide the code to do that I will give it a try, also a code to end the preg replace since this value is the only exception

TFCash 03-26-2014 03:00 PM

<?php print nl2br($recipient->address_street) ?>

should do it for you :thumbsup

KickAssJesse 03-26-2014 03:09 PM

looks like you may need to update your function

TFCash 03-26-2014 03:19 PM

Quote:

Originally Posted by KickAssJesse (Post 20028934)
looks like you may need to update your function

Sorry went back and re-read it, I thought it was printing on one line, and he wanted it to print on both :(

<?php print str_replace('\\r\\n','', $recipient->address_street) ?>

Got to stop pulling these all nighters!

mkx 03-26-2014 03:33 PM

hmm the code seems like it would work but isn't make any difference, still echoing with the new line

mkx 03-26-2014 03:42 PM

got it working with this :) thanks a bunch!

<?php print str_replace("\n",', ', $recipient->address_street) ?>

TFCash 03-26-2014 03:43 PM

Quote:

Originally Posted by mkx (Post 20028958)
hmm the code seems like it would work but isn't make any difference, still echoing with the new line


Can you look and see how it is listed in your database ?? Sometimes it's just a \n so then you'd use

<?php print str_replace('\\n','', $recipient->address_street) ?>

TFCash 03-26-2014 03:44 PM

Quote:

Originally Posted by mkx (Post 20028974)
got it working with this :) thanks a bunch!

<?php print str_replace("\n",', ', $recipient->address_street) ?>

Glad to hear it :)


All times are GMT -7. The time now is 01:26 PM.

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