[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-07-2007, 05:22 PM   #1 (permalink)
NamePros Member
 
Join Date: Sep 2004
Posts: 180
118.70 NP$ (Donate)

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, 05:34 PM   #2 (permalink)
New Member
 
Join Date: May 2007
Posts: 13
0.00 NP$ (Donate)

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, 01:08 PM   #3 (permalink)
NamePros Regular
 
monaco's Avatar
 
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 695
314.80 NP$ (Donate)

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, 01:11 PM   #4 (permalink)
Adrian
 
Hitch's Avatar
 
Join Date: Aug 2005
Location: Uk, South Yorkshire
Posts: 1,227
16.00 NP$ (Donate)

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

Animal Rescue Third World Education Find Marrow Donors!
Quote:
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>'; ?>
__________________
NamePros
Hitch is offline  
Old 05-09-2007, 12:34 AM   #5 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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
Quote:
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>' ?>   
<? print '<div align="center">Even More Centered Test</div>' ?>
Peter is offline  
Old 05-09-2007, 01:16 AM   #6 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

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, 03:33 AM   #7 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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>
Because you don't need PHP for that.
Dan is offline  
Old 05-09-2007, 03:53 AM   #8 (permalink)
NamePros Regular
 
Join Date: Oct 2006
Posts: 918
40.00 NP$ (Donate)

neroux has a spectacular aura aboutneroux has a spectacular aura about


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

muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com

-- Do not let others be treated this way!
neroux is offline  
Old 05-09-2007, 08:59 PM   #9 (permalink)
NamePros Member
 
Join Date: Jun 2005
Location: New Zealand
Posts: 95
13.00 NP$ (Donate)

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, 12:41 AM   #10 (permalink)
NamePros Regular
 
Join Date: Feb 2006
Posts: 588
1,620.95 NP$ (Donate)

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 all


Don't use PHP - it adds processing time.

Always use HTML when possible.
jerometan is offline  
Old 05-10-2007, 12:52 AM   #11 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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
Quote:
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.

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, 04:55 AM   #12 (permalink)
NamePros Member
 
Join Date: Jun 2005
Location: New Zealand
Posts: 95
13.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:05 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85