Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-15-2013, 01:49 PM   #1
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
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 ?>
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 01:55 PM   #2
woj
<&(©¿©)&>
 
woj's Avatar
 
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
obviously remove new line characters...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 01:58 PM   #3
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
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 ?>
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 02:06 PM   #4
HomerSimpson
Too lazy to set a custom title
 
HomerSimpson's Avatar
 
Industry Role:
Join Date: Sep 2005
Location: Springfield
Posts: 13,826
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
__________________
Make a bank with Chaturbate - the best selling webcam program
Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!!

PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email:
HomerSimpson is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 02:11 PM   #5
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
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 ?>
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 02:21 PM   #6
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,073
Are you just wanting to populate a variable and echo to the screen?

<?php
$x = "hello";
echo $x
?>
__________________
Live Sex Shows
lezinterracial is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 02:31 PM   #7
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
No i am trying to echo $hi->hello on one line

$hi->hello =

"hello how
are you
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:16 PM   #8
Dankasaur
So Fucking Fossilized
 
Industry Role:
Join Date: Sep 2011
Posts: 1,432
Quote:
Originally Posted by mkx View Post
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 ?>
Dankasaur is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:22 PM   #9
helterskelter808
So Fucking Banned
 
Industry Role:
Join Date: Sep 2010
Posts: 3,405
Quote:
Originally Posted by mkx View Post
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; 
?>
helterskelter808 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:29 PM   #10
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,223
Would PHP trim work?

echo trim($hi,"/n");
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:42 PM   #11
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,078
never mind... Next time I will read the thread first ;p
__________________
All cookies cleared!

Last edited by sarettah; 05-15-2013 at 03:45 PM..
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:47 PM   #12
helterskelter808
So Fucking Banned
 
Industry Role:
Join Date: Sep 2010
Posts: 3,405
Trim is for stripping at the beginning and end of a string.
helterskelter808 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 03:56 PM   #13
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,223
Quote:
Originally Posted by helterskelter808 View Post
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?
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 04:06 PM   #14
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,078
Quote:
Originally Posted by Colmike7 View Post
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?
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); ?>

.
__________________
All cookies cleared!

Last edited by sarettah; 05-15-2013 at 04:12 PM..
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 04:07 PM   #15
helterskelter808
So Fucking Banned
 
Industry Role:
Join Date: Sep 2010
Posts: 3,405
Quote:
Originally Posted by Colmike7 View Post
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?
The code works in the example I gave, but I can't say if it would work in every situation.
helterskelter808 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 04:16 PM   #16
Dankasaur
So Fucking Fossilized
 
Industry Role:
Join Date: Sep 2011
Posts: 1,432
Quote:
Originally Posted by sarettah View Post
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.
Dankasaur is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 04:40 PM   #17
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,078
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.

.
__________________
All cookies cleared!

Last edited by sarettah; 05-15-2013 at 04:44 PM..
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 05:10 PM   #18
woj
<&(©¿©)&>
 
woj's Avatar
 
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
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...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 05:13 PM   #19
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,078
Quote:
Originally Posted by woj View Post
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...
Ah cmon WOJ we are only on post 19.


.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2013, 05:23 PM   #20
Dankasaur
So Fucking Fossilized
 
Industry Role:
Join Date: Sep 2011
Posts: 1,432
Quote:
Originally Posted by woj View Post
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...
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.
Dankasaur is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.