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

mkx 05-15-2013 01:49 PM

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 ?>

woj 05-15-2013 01:55 PM

obviously remove new line characters... :2 cents:

mkx 05-15-2013 01:58 PM

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 ?>

HomerSimpson 05-15-2013 02:06 PM

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

mkx 05-15-2013 02:11 PM

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 ?>

lezinterracial 05-15-2013 02:21 PM

Are you just wanting to populate a variable and echo to the screen?

<?php
$x = "hello";
echo $x
?>

mkx 05-15-2013 02:31 PM

No i am trying to echo $hi->hello on one line

$hi->hello =

"hello how
are you

Dankasaur 05-15-2013 03:16 PM

Quote:

Originally Posted by mkx (Post 19626521)
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 ?>

Code:

<?php
$x = str_replace(array("\r\n","\r"),"",$hi->hello);
$x = strip_tags($x);
print $x ?>


helterskelter808 05-15-2013 03:22 PM

Quote:

Originally Posted by mkx (Post 19626521)
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 ?>

Why would that work? What is $x? And what tags are you stripping? Try this:

Code:

<?php
$hi->hello = "hello how
are you";
$one_line = trim(preg_replace('/\s+/', ' ', $hi->hello));
print $one_line;
?>


Colmike9 05-15-2013 03:29 PM

Would PHP trim work?

echo trim($hi,"/n");

sarettah 05-15-2013 03:42 PM

never mind... Next time I will read the thread first ;p

helterskelter808 05-15-2013 03:47 PM

Trim is for stripping at the beginning and end of a string.

Colmike9 05-15-2013 03:56 PM

Quote:

Originally Posted by helterskelter808 (Post 19626655)
Trim is for stripping at the beginning and end of a string.

Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above? :upsidedow

sarettah 05-15-2013 04:06 PM

Quote:

Originally Posted by Colmike7 (Post 19626662)
Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above? :upsidedow

replace is the easiest way. However, in this case it would seem to me that there is some disagreement on what needs to be replaced. The OP says the phrase comes out on 2 lines. If it is an html presentation that would indicate that there is a <br> in the phrase. If it is a text presentation that would indicate that there is a carriage return/linefeed in the phrase.

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); ?>

.

helterskelter808 05-15-2013 04:07 PM

Quote:

Originally Posted by Colmike7 (Post 19626662)
Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above? :upsidedow

The code works in the example I gave, but I can't say if it would work in every situation.

Dankasaur 05-15-2013 04:16 PM

Quote:

Originally Posted by sarettah (Post 19626676)
replace is the easiest way. However, in this case it would seem to me that there is some disagreement on what needs to be replaced. The OP says the phrase comes out on 2 lines. If it is an html presentation that would indicate that there is a <br> in the phrase. If it is a text presentation that would indicate that there is a carriage return/linefeed in the phrase.

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); ?>

.

Bingo. :thumbsup

sarettah 05-15-2013 04:40 PM

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.

.

woj 05-15-2013 05:10 PM

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

sarettah 05-15-2013 05:13 PM

Quote:

Originally Posted by woj (Post 19626744)
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

Ah cmon WOJ we are only on post 19.


.

Dankasaur 05-15-2013 05:23 PM

Quote:

Originally Posted by woj (Post 19626744)
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

Not to mention that if he goes off privately with you instead of collectively being helped, what if someone else runs into this problem? Nothing like finding a similar problem thread and then being disappointed because nobody posted the fix.


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