center an image in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

center an image in php

Post by podarum »

Hi, I'm printing an image from an if statement, and I want to centre it.. any idea how.. so the last line in echo I'd like to centre it horizontally on the page.. Thanks

Code: Select all

 
{if ($Utilization2 == 0)
{echo "<table><td style=text-align:justify> Your utilization position is solid and not an issue with most credit grantors in this regard. The debt-to-credit ratio is <b>".$Utilization2;print " %</b>";print". You are not carrying a balance, but would want to show a higher utilization % to demonstrate that you use the credit assigned and able to pay it off. </td></table>";
echo'<img src="images/Process5 0a.png" width="350" height="200">';}
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: center an image in php

Post by mybikeisgreen »

Have you tried using <center><img src="..."></center>?
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: center an image in php

Post by podarum »

Yeah, tried that , it didn't work...
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: center an image in php

Post by mybikeisgreen »

Did you try

style=text-align:center
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: center an image in php

Post by podarum »

Yup, just tried that and all it did was center the text only but not the image...
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: center an image in php

Post by mybikeisgreen »

did you try

style="margin-left:auto;margin-right:auto;"
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: center an image in php

Post by podarum »

hehehe..yes, tried that and nothing happened
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: center an image in php

Post by s.dot »

Centering an image will only center it within the element it's contained in.
Try making your <td> with a width attribute like <td width="500">text<center><img></center></td>.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: center an image in php

Post by podarum »

I tried tis and got error... is this what you meant?

Code: Select all

 
{if ($Utilization2 == 0)
{echo "<table> <td width="500">text<center><img></center></td> Your utilization position is solid and not an issue with most credit grantors in this regard. The debt-to-credit ratio is <b>".$Utilization2;print " %</b>";print". You are not carrying a balance, but would want to show a higher utilization % to demonstrate that you use the credit assigned and able to pay it off. </td></table>";
echo '<img src="images/Process5 0a.png" width="350" height="200">';}
 
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: center an image in php

Post by Griven »

Remove that <center><img></center> bit.

Then use this at the end:

Code: Select all

echo '<div style="width: 100%; text-align: center"><img src="images/Process5 0a.png" width="350" height="200" /></div>';
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: center an image in php

Post by podarum »

Thank you .. that worked...
Post Reply