Jump to content

Archived

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

tipjones

How to tab text when displaying in php

Recommended Posts

Hello,

I am new to php and wanted to know how to tab text when displaying in php! For example, I want to output the following: Hello World    !. After World I want to tab and then print !.  I know in html this can be done by putying \t, I have tired this in php and it didn't work. ANY ADVICE WILL BE A GREAT HELP!!

 

Thanks In Advance

 

Share this post


Link to post
Share on other sites

echo "Hello World\t!";

Will work as long as you enclose it all in double quotes

Share this post


Link to post
Share on other sites

Thanks, 

This helps but when using \t it only allow me to tab once, how do I tab multiple of times. Or is it possile to include multiple spaces. I know in html you can include   how may times you want a space and it will include a space. Also, I know you can inculde" " in php and it will give you one space but if you include "          "it will also give one space which should be about four spaces.

I am trying to output the following but with several spaces in between each heading:

Name:                          Phone:                                      Address:

 

Any help will be a great help!!

Share this post


Link to post
Share on other sites

Remember Mr. Tip Jones, what you echo in php is html. Multiple tabs: \t\t\t\t\t\t\t\t\t\t\t\t. A line break: <br />. Multiple spaces:      .

 

In your case, I would recommend a table, hold the chairs.

You can do so in your php like so:

echo "<table>";

Share this post


Link to post
Share on other sites

bobleny,

Thanks for the input!! However, I don't understand fully what you mean. Could you give me a in detail example. When I did the following in my code: echo "The big brown\t\t\t\t\t\t\t\t\t\tdog!";

It printed The big brown dog. For some reason it is not printing the multiple tabs I have. What can I do to make it print ALL of the tabs. I really need for this to print with the multiple tabs. PLEASE HELP!

Share this post


Link to post
Share on other sites

When you say.....

 

For some reason it is not printing the multiple tabs I have.

 

are you looking in the outputed html source? That is what is affected by \t. As for adding tabs to html, well, thats html not php.

Share this post


Link to post
Share on other sites

thorpe,

Thanks for the prompt response. I am looking in my php file b/c there is where I want to echo the statement so in my php file I have echo "The big brown\t\t\t\t\t\t\t\t\t\tdog!"; and only on tab is printing. I have this code between  <?php and ?>.

Share this post


Link to post
Share on other sites

When you view this page in your browser, right click and go to view source, is the output tabed?

Share this post


Link to post
Share on other sites

thorpe,

No it isn't! Why is this happening, in my soruce code it is tabbed! Can this be fixed?

 

Share this post


Link to post
Share on other sites

Post your exact (php) code and the exact html output it produces (using view source).

Share this post


Link to post
Share on other sites

thrope,

I am new to this forum and don't know about view source. Hope you can view the source code.

<code>

<body bgcolor="#CCCCCC" text="#000000">

<p align="center"> </p>

<p align="center"><strong><font size="3" face="Georgia"><em><font size="5">GEORGIA</font></em></strong></p>

<p align="center"><strong><font size="3" face="Georgia"><em><font size="5">UNIFORM TRAFFIC CITATION, SUMMONS AND ACCUSATION</font></em></strong></p>

</body>

<?php

 

 

    $dbcnx = @mysql_connect("localhost", "tiffanie",

  "272420");

 

 

if (!$dbcnx) {

    echo( "<p>Unable to connect to the " .

          "database server at this time.</p>"

  );

    exit();

  }

 

 

 

 

  if (! @mysql_select_db("AMDU") ) {

    echo( "<p>Unable to locate " .

          "database at this time.</p>" );

    exit();

  }

 

 

echo('<br>');

//Retrieving values for sect3 of ticket

 

$weather = $_REQUEST['weather'];

$traffic = $_REQUEST['traffic'];

$lighting = $_REQUEST['lighting'];

$road_cond= $_REQUEST['rdcond'];

$road_type = $_REQUEST['rdtype'];

$comvecinfo = $_REQUEST['comvecinfo'];

/*

echo $weather;

echo '<br>';

echo $traffic;

echo '<br>';

echo $lighting;

echo '<br>';

echo $road_cond;

echo '<br>';

echo $road_type;

echo '<br>';

echo $comvecinfo;

echo '<br>';

*/

$sql="SELECT Lic FROM tickets";

$r = mysql_query($sql);

$val = mysql_fetch_assoc($r);

$tempval = $val['Lic'];

 

 

//Entering data from sect3 of ticket into database

$result = mysql_query("UPDATE tickets SET weather = '$weather', traffic = '$traffic', lighting = '$lighting', road_cond = '$road_cond', road_type =

 

'$road_type', comvecinfo = '$comvecinfo' WHERE Lic ='$tempval'");

 

$sql1="SELECT State FROM tickets";

$test = mysql_query($sql1);

$value = mysql_fetch_assoc($test);

$tempval1 = $value['State'];

 

 

$result1 = mysql_query("SELECT Lic,LicClass_Type, Lic_Endorsements, Lic_Expiration,First_Name, Middle_Name,Last_Name FROM $tempval1 WHERE Lic ='$tempval'"); 

//$val1 = mysql_fetch_assoc($result1);

 

 

while ($row = mysql_fetch_array($result1,MYSQL_ASSOC))

{

 

echo 'Name: ' . $row['First_Name'] ."\t".$row['Middle_Name'] ."\t".$row['Last_Name'] ."\t

\t\t\t\t".'License Class: ' .$row['LicClass_Type']. '<br/>' ;

 

 

}//while

 

 

?>

</code>

The output is:Name: Tiffanie Nicole Jones License Class: C

 

Share this post


Link to post
Share on other sites
I am new to this forum and don't know about view source.

 

Thats exactly what I am saying. \t affects the outputed source only, not how your output is displayed within your browser. If (when viewing your page within your browser) you right click and go to view source you will see the html output. There you will notice the tabs are in affect.

Share this post


Link to post
Share on other sites

tourpe,

This is my view source code:

 

<body bgcolor="#CCCCCC" text="#000000">

<p align="center"> </p>

<p align="center"><strong><font size="3" face="Georgia"><em><font size="5">GEORGIA</font></em></strong></p>

<p align="center"><strong><font size="3" face="Georgia"><em><font size="5">UNIFORM TRAFFIC CITATION, SUMMONS AND ACCUSATION</font></em></strong></p>

</body>

<br>Name: Tiffanie Nicole Jones  Jones<br/>

 

Is there any way to make the multiple tabs show?

Share this post


Link to post
Share on other sites

Oh shoot, I screwed up...

 

Thorpes right. That will only effect the source output's display.

 

I just checked the HTML entities, and I don't think there is a way to do tabs. However, you can still use this:

echo "stuf           !";

 

That should do what you want it to do.

 

Mind you, I still think you need to use a different method of displaying data. Such as tables, or css.....

Share this post


Link to post
Share on other sites

what you echo in php is html.

 

While I do understand you, that statement is not entirely true. The most frequent use for PHP is creating dynamic HTML, but you can output any type of content and it doesn't necessarily have to be a browser.

Share this post


Link to post
Share on other sites

You really should however be using CSS to style your html.

Share this post


Link to post
Share on other sites

Though I have no clue what it is that you are trying to do, I am glad I could help! ;)

However, for the records, I do not condone the use of " ," nor do I often suggest the use of tables....

 

You really should however be using CSS to style your html.

Share this post


Link to post
Share on other sites

×
×
  • 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.