![]() |
quick simple php question
Say that I have some data in my sql database that reads
"hello how are you" How do I make it echo on the same line so it displays? "Hello how are you" Here is my current code to echo it = <?php print $hi->hello ?> |
obviously remove new line characters... :2 cents:
|
howdy woj, im extremely new to php, tried googling it but was a bit confusing. can anyone tell me what I should replace this with? I can't modify the db at all
<?php print $hi->hello ?> |
you need to remove new lines (or <br> tags) from that string
new lines $x = str_replace(array("\r\n","\r"),"",$x); tags (will strip all) $x = strip_tags($x); and then echo it |
sorry im still a bit confused, tried this with no luck =
<?php $x = str_replace(array("\r\n","\r"),"",$x); $x = strip_tags($hi->hello); print $x ?> |
Are you just wanting to populate a variable and echo to the screen?
<?php $x = "hello"; echo $x ?> |
No i am trying to echo $hi->hello on one line
$hi->hello = "hello how are you |
Quote:
Code:
<?php |
Quote:
Code:
<?php |
Would PHP trim work?
echo trim($hi,"/n"); |
never mind... Next time I will read the thread first ;p
|
Trim is for stripping at the beginning and end of a string.
|
Quote:
|
Quote:
If he needs to get rid of a <br> then strip_tags does that or you could include it in a replace. If he needs to get rid of a carriage return/linefeed then the replace can do that. Since we don't know exactly which needs to be done then a solution like dankasaur's that covers both possibilities will work. A one line solution would be like <?php print str_replace(array("\r\n","\r","<br>")," ",$hi->hello); ?> . |
Quote:
|
Quote:
|
Just an add on.
I was assuming that it was a <br> in there. It could be all sorts of html code that is invisble to the eye (hidden divs, etc) so probably to make sure all possible tags are covered then a better one line solution might be <?php print strip_tags(str_replace(array("\r\n","\r")," ",$hi->hello)); ?> And I tend not to use \r\n so my way would probably be (actually my way would be to change it in the db but the OP says he does not have that access, so) <?php print strip_tags(str_replace(array(chr(10),chr(13))," ",$hi->hello)); ?> which is basically the same thing just different. The OP needs to look under the sheets (view source) and see exactly what is in the output that is causing the line break in order to derive the best solution. . |
mkx,
just hit me up on icq: 33375924 and I'll hook you up... before one line of code question turns into a 3 page thread... :1orglaugh |
Quote:
. |
Quote:
|
All times are GMT -7. The time now is 08:19 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123