![]() |
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 |
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 ;] |
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
|
<?php print nl2br($recipient->address_street) ?>
should do it for you :thumbsup |
looks like you may need to update your function
|
Quote:
<?php print str_replace('\\r\\n','', $recipient->address_street) ?> Got to stop pulling these all nighters! |
hmm the code seems like it would work but isn't make any difference, still echoing with the new line
|
got it working with this :) thanks a bunch!
<?php print str_replace("\n",', ', $recipient->address_street) ?> |
Quote:
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) ?> |
Quote:
|
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