Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Tables 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
How does a table (text) code in PHP differ to an HTML table.

If I had an HTML table and used its syntax, I notice \t\t in front of some tags, and \t in front of others. Is there a reference anywhere to such differences or am I hoping for too much? Many thanks.
 
The "\t" (tab) characters are used for formating the source so it is more readable for humans. Browsers ignore them. You can leave them out. Since PHP is generating HTML, if you generate correct HTML, there will be no problems.

Ken
 
Thanks Ken.
I know its lazy, and probably not good HTML?, but I was using Frontpage to design my table structure and hoped to modify tags or whatever so I could echo it on a page to display session variable values. If I paste in the HTML code it does not like it. I have looked around but end up with database tables!! Regards
 
Typically my problem. I have this code which I tried to run and it reports an error:

Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';'

Code I tried is:

echo "<table border="1" width="75%" id="table1">
<tr>
<td bgcolor="#C0C0C0" colspan="2"><b><font face="Arial">Name</font></b></td>
</tr>
<tr>
<td width="375" bgcolor="#C0C0C0"><b><font face="Arial">Product</font></b></td>
<td bgcolor="#C0C0C0"><b><font face="Arial">Quantity</font></b></td>
</tr>
<tr>
<td width="375">a</td>
<td>b</td>
</tr>
</table>";


Many thanks.
 
Oh dear, by now you should understand this.

How do you delimit strings in PHP? With quotes, either single or double.
How long is the string? From opening quote to a matching closing quote.

So, you're echoing this:
Code:
echo "<table border="
PHP has no problem with that. From then on, it is expecting something to happen. Since following that is your html code, php gets confused and throws out an error. It is that simple.

Now, if you want to have a quote inside a string, you need to escape that quote so that php knows it is not the quote marking the end of the string but rather a quote within the string. However, since I mentioned that php can delimit strings with either double or single quotes, a much easier solution is to just wrap the string in single quotes and use double quotes in attributes:
Code:
echo '<table border="1" width="75%" id="table1">
    <tr>
      ...
    </tr>
</table>';
 
Quotes inside quotes. Again. If you don't understand this, you're not going to get very far with PHP.



If a doublequote starts a string, such as:

echo "<table border=

Then it would be reasonable to expect that a doublequote ends the string such, as here:

"1

So PHP correctly attempts to interpret your code as:

echo " <- start string
<table border=" <- end string
1 <- bare number
" <- start another string
width=" <- end string
75% <- bare text
" <- start another string
id=" <- end string

Either:[ul][li]use singlequotes to delineate your entire string and doublequotes inside[/li][li]escape all the interior doublequotes (change '"' to '\"')[/li][/ul]

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thankyou guys, got it, tables up and running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top