Jump to content

Echo spacing.


joe1986

Recommended Posts

Hi there,

 

I think its a bit of a simple one really but im a PHP newbie. Im trying to put a space in between the output values (shown below) and I thought the ."  ". in the middle would solve this problem, but it turns out not; and im pulling my hair out. The code I have for output reads:

 

while ($row = mysql_fetch_array($result)) {
   echo "  ".$row{'subject'}."  ".$row{'data'}."<br>";

 

and the output is displayed as:

 

"Subject Data"

 

I want to put more spaces in between these two values, e.g. "Subject _________ Data" (obviously without the _)

 

Could anybody please help me?

 

Cheers,

 

Joe

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/
Share on other sites

For it to display on a webpage, you would need to use   and strpad will be your best friend.

 

If it is to be displayed in a text file, strpad is still the way, but instead of   just use the regular space character.

 

 echo "  ". strpad($row{'subject'}, 10, " ") . $row{'data'}."<br>";

 

EDIT:

I remember having issues with this using the   so I am not sure if that will work in this case. If not just manually add them in.

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798176
Share on other sites

Thanks for the quick reply. It is to be displayed on a webpage within a html table. Im not quite sure where to insert the   or how to manually add the space in. I tried the strpad code you suggested, but no luck. any suggestions?

 

thanks again for the reply.

 

Joe

 

For it to display on a webpage, you would need to use   and strpad will be your best friend.

 

If it is to be displayed in a text file, strpad is still the way, but instead of   just use the regular space character.

 

 echo "  ". strpad($row{'subject'}, 10, " ") . $row{'data'}."<br>";

 

EDIT:

I remember having issues with this using the   so I am not sure if that will work in this case. If not just manually add them in.

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798185
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.