tipjones Posted January 18, 2009 Share Posted January 18, 2009 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 Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted January 18, 2009 Share Posted January 18, 2009 echo "Hello World\t!"; Will work as long as you enclose it all in double quotes Quote Link to comment Share on other sites More sharing options...
corbin Posted January 18, 2009 Share Posted January 18, 2009 You can also put a tab in the echo statement. Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 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!! Quote Link to comment Share on other sites More sharing options...
bobleny Posted January 18, 2009 Share Posted January 18, 2009 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>"; Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 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! Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 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 ?>. Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 When you view this page in your browser, right click and go to view source, is the output tabed? Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 thorpe, No it isn't! Why is this happening, in my soruce code it is tabbed! Can this be fixed? Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 Post your exact (php) code and the exact html output it produces (using view source). Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 18, 2009 Author Share Posted January 18, 2009 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? Quote Link to comment Share on other sites More sharing options...
bobleny Posted January 18, 2009 Share Posted January 18, 2009 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..... Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 19, 2009 Share Posted January 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
tipjones Posted January 19, 2009 Author Share Posted January 19, 2009 bobleny Thanks! I think your approach will work!! Quote Link to comment Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 You really should however be using CSS to style your html. Quote Link to comment Share on other sites More sharing options...
bobleny Posted January 19, 2009 Share Posted January 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.