NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] PHP Help

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-07-2007, 06:22 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Sep 2004
Posts: 170
Fallen is an unknown quantity at this point
 



PHP Help


First of all I'm new to php and I need some text to be centered using php code. How do I go aobut doing that? Thanx in advance.
__________________
One Thing I [I as in you] Have Learned | Share one of your life lessons.
Experiencing College | A walk through of my first college experience.
Fallen is offline  
Old 05-07-2007, 06:34 PM   #2 (permalink)
New Member
Join Date: May 2007
Posts: 13
lsw-computing is an unknown quantity at this point
 



Welcome to PHP

You wouldn't center text in PHP, it would still be done in HTML, just being sent to the browser using the php print() construct:

PHP Code:
<?php
print "<div style='text-align:center'>This text will be centered</div>";
?>
If you are looking for some PHP tutorials, head over to http://www.webjuniors.com/showthread.php?t=249 - quite a few tutorials I have written, I try to add one every couple of days
lsw-computing is offline  
Old 05-08-2007, 02:08 PM   #3 (permalink)
NamePros Regular
 
monaco's Avatar
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 689
monaco will become famous soon enough
 



Don't count on using style attributes inside div tags; not all platforms support this (think IE on pocket PC for one). It won't validate as anything but html 4.01 transitional or lower, but you can use this:
PHP Code:
<? print '<div align="center">Centered Text</div>' ?>
.
__________________
My Website | My Blog
monaco is offline  
Old 05-08-2007, 02:11 PM   #4 (permalink)
Senior Member
 
Hitch's Avatar
Join Date: Aug 2005
Location: Uk, South Yorkshire
Posts: 1,225
Hitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to behold
 


Winner
PHP Programming - May 2007
Animal Rescue Third World Education Find Marrow Donors!
Originally Posted by monaco
Don't count on using style attributes inside div tags; not all platforms support this (think IE on pocket PC for one). It won't validate as anything but html 4.01 transitional or lower, but you can use this:
PHP Code:
<? print '<div align="center">Centered Text</div>' ?>
.
IF you use the adove, remember to add a ; after the '

PHP Code:
  <? print '<div align="center">Centered Text</div>'?>
__________________
Cueburst - Support System - FAQ Knowledge Base, Tickets and more.
Hitch is offline  
Old 05-09-2007, 01:34 AM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by Hitch
IF you use the adove, remember to add a ; after the '

PHP Code:
  <? print '<div align="center">Centered Text</div>'?>
It is not actually necessary in this case as there is a closing php tag (although it is advised)

Try it and see the following is perfectly valid php:-

PHP Code:
<? print '<div align="center">Centered Text</div>' ?>   
????: NamePros.com http://www.namepros.com/programming/325332-resolved-php-help.html
<? print '<div align="center">Even More Centered Test</div>' ?>
Peter is offline  
Old 05-09-2007, 02:16 AM   #6 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
I'll do ya one better If all you're doing is printing something out and you're using short tags (as you are above), you can also dispense with print/echo and just use the '=' character:

PHP Code:
<?='<div align="center">Centered Text</div>'?>
cef is offline  
Old 05-09-2007, 04:33 AM   #7 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Or you could just use:
PHP Code:
<div align="center">Centered Text</div
????: NamePros.com http://www.namepros.com/showthread.php?t=325332
Because you don't need PHP for that.
Dan is offline  
Old 05-09-2007, 04:53 AM   #8 (permalink)
NamePros Regular
Join Date: Oct 2006
Posts: 963
neroux has a spectacular aura aboutneroux has a spectacular aura about
 



Originally Posted by Dan
Because you don't need PHP for that.
Fully seconded.
__________________
Paris loves CityPics

-- Do not let others be treated this way!
neroux is offline  
Old 05-09-2007, 09:59 PM   #9 (permalink)
NamePros Member
Join Date: Jun 2005
Location: New Zealand
Posts: 95
music_man is on a distinguished road
 



Don't use short tags.

Use <?php

Also, make sure you add an ; after:

Quote:
<?php echo 'test'; ?>
Also, you don't need php for straight HTML, it parses slower.
__________________
Self-service
My homepage
music_man is offline  
Old 05-10-2007, 01:41 AM   #10 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



Don't use PHP - it adds processing time.

Always use HTML when possible.
jerometan is offline  
Old 05-10-2007, 01:52 AM   #11 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by music_man
Don't use short tags.

Use <?php

Also, make sure you add an ; after:



Also, you don't need php for straight HTML, it parses slower.
Most of that is very true, you should use standard php tags (<?php ?>) as it avoids conflict and it is the only 1 guaranteed to work (the others can be disabled or are deprecated and can be removed at any time).

And you are correct extra processing time will be taken up if you have non php in php tags as it will go through the php engine for no reason.
????: NamePros.com http://www.namepros.com/showthread.php?t=325332

Regarding the ; it is not necessary in the above example as the ?> comes directly after the command (I double checked and it worked 100%). However of course best practice always dictates the use of it.
Peter is offline  
Old 05-10-2007, 05:55 AM   #12 (permalink)
NamePros Member
Join Date: Jun 2005
Location: New Zealand
Posts: 95
music_man is on a distinguished road
 



True enough. If you want another echo without using ; e.g.

Quote:
<?php
echo 'test'
echo 'hi'
?>
That comes up with a parse error.
__________________
Self-service
My homepage
music_man is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:31 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger