Author |
Message |
wiz
Involved


Joined: Oct 09, 2006
Posts: 413
Location: UK
|
Posted:
Wed Sep 17, 2008 5:40 am |
|
Hi guys, i am writing a very simple table to display a price list. But i get this error when browsing to the page...
Code:<tr>
<td><div align='center'>Argos</div></td>
<td><div align='center' class='style1'>£322</div></td>
<td><div align='center' class='style2'>£314</div></td>
</tr>
|
The output returns as this...
Argos £322 £314
What is this and why is it happening? Any ideas?
Cheers |
|
|
|
 |
warren-the-ape
Worker


Joined: Nov 19, 2007
Posts: 196
Location: Netherlands
|
Posted:
Wed Sep 17, 2008 5:59 am |
|
Those single quotes should be double quotes to begin with;
align='center' class='style1' > align="center" class="style1"
Your charset probably doesn't work well with the £ symbol used in this way, you should use the html character code instead;
£ > £
€ > €
£322 > £322 |
|
|
|
 |
wiz

|
Posted:
Wed Sep 17, 2008 6:08 am |
|
ahhh got it
Changed the £ to £ and its fixed it. cheers
The reason for the single quotes, is because the table is inside an echo statement, therefore the outer statements are double quotes
Cheers For that little oversight on my part |
|
|
|
 |
Gremmie
Former Moderator in Good Standing

Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Wed Sep 17, 2008 6:53 am |
|
I don't think that technically it matters if the quotes in HTML attributes are single or double.
PHP needs triple quoted strings like Python does to get around the quote nonsense. |
_________________ Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module |
|
|
 |
warren-the-ape

|
Posted:
Wed Sep 17, 2008 7:16 am |
|
Gremmie wrote: | I don't think that technically it matters if the quotes in HTML attributes are single or double. |
Jeps true, my bad.
Like you said, its faster to code in PHP as well. Although i personally use double quotes whenever possible, even if it takes some extra time to code  |
|
|
|
 |
wiz

|
Posted:
Wed Sep 17, 2008 7:20 am |
|
well no, in my experience, singles are as good as doubles.. however you will get a syntax error if you do something like this..
echo "<a href ="ravenphpscripts.com">RPS </a>"; |
|
|
|
 |
Gremmie

|
Posted:
Wed Sep 17, 2008 3:29 pm |
|
Some people say that there is a performance boost if you use single quotes in PHP, as the parser doesn't have to do variable interpolation inside single quoted strings. It is also easier to output HTML attributes:
echo '<a href="http://yahoo.com">Yahoo</a>';
No escaping of the double quotes in the HREF attribute is needed.
Of course this makes it harder to output PHP variables, as you then have to do something like this:
echo '<a href="http://yahoo.com">' . $link_title . '</a>';
But then I learned a trick from another site that says in this case, you can make your code faster by losing the "." concatenation operator, and simply use the comma to pass multiple argumets to the echo statement:
echo '<a href="http://yahoo.com">', $link_title, '</a>';
These days, however, I am not outputing HTML from the code directly, I am coding with templates. I like cleanly separating business logic from presentation. |
|
|
|
 |
wiz

|
Posted:
Wed Sep 17, 2008 5:05 pm |
|
So a , is faster than a .? |
|
|
|
 |
Gremmie

|
Posted:
Wed Sep 17, 2008 7:15 pm |
|
Apparently, according to one of the Zend developers. |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Thu Sep 18, 2008 12:28 am |
|
Peaked my interest when you first mentioned that Gremmie, did you ever run a POC to see what the performance gains might be (I'm curious)?
Personally I prefer '.$var.' because I find that easier to read and my editor copes better with syntax error highlighting but it's something I might 'force' myself to use on a large piece of code if benefits were tangible. |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Thu Sep 18, 2008 6:05 am |
|
The explanation of it by the developer Gremmie mentioned sure made sense to me. I started changing over to using it after I read that article, but no POC. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
Gremmie

|
Posted:
Thu Sep 18, 2008 8:08 am |
|
I'm not sure what you mean by POC, but I have not benchmarked it if that is what you meant. It would intuitively seem to be faster as PHP does not have to keep appending to a string, possibly allocating more memory as the string grows. But it would be interesting to measure it for various sizes of strings and the number of items to be printed.
I like the comma syntax better as I think it more clearly expresses what I am trying to do: print out a sequence of strings versus building one long string. But I admit that is totally a matter of personal taste. |
|
|
|
 |
testy1
Involved


Joined: Apr 06, 2008
Posts: 484
|
Posted:
Thu Sep 18, 2008 5:11 pm |
|
I did some testing on this and found that it depends largerly on how intensive the script is.I would like to see some one else try this to see if it can be verified.This was all done locally and i used Ctrl-F5 each time to completely refresh the page.I used Firefox 3.0.1. I did 5 runs of each and use the average of the 5 results.
The file is located here..... Only registered users can see links on this board! Get registered or login!
Is there a better way I can test this.
Quote: |
',$test1,'
3.444950
3.363278
3.362509
3.508481
3.391729
Average: 3.4141894
'.$test1.'
7.187403
7.114683
6.863072
6.634337
7.788790
Average: 7.117657
".$test1."
6.648216
7.400411
6.452212
7.305614
6.905950
Average: 6.9424806
|
|
|
|
|
 |
Gremmie

|
Posted:
Thu Sep 18, 2008 6:10 pm |
|
Test in a loop. That file is only testing double quote concatenation, unless you changed it between runs. |
|
|
|
 |
testy1

|
Posted:
Thu Sep 18, 2008 6:17 pm |
|
yes i changed it between runs, how would i test it via a loop |
|
|
|
 |
Gremmie

|
Posted:
Thu Sep 18, 2008 8:29 pm |
|
Start your timer, do a whole bunch of the same thing in a for loop, end timer and compute elapsed time. Repeat for next type of test.
E.g.
Code:
capture time t1
for ($i = 0; i < a_large_number; ++i)
{
// do your test 1
}
capture time t2
print elapsed (t2 - t1)
capture time t1
for ($i = 0; i < a_large_number; ++i)
{
// do your test 2
}
capture time t2
print elapsed (t2 - t1)
|
Etc. |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Thu Sep 18, 2008 10:23 pm |
|
All that aside ....
XHTML standards compliance requires that all attributes be in double quotes, amongst other things.  |
|
|
|
 |
testy1

|
Posted:
Thu Sep 18, 2008 10:40 pm |
|
somebodies always got to wreck the party  |
|
|
|
 |
warren-the-ape

|
Posted:
Fri Sep 19, 2008 1:25 am |
|
Raven wrote: | XHTML standards compliance requires that all attributes be in (double) quotes, amongst other things. |
wiz wrote: | well no, in my experience, singles are as good as doubles.. however you will get a syntax error if you do something like this..
echo "<a href ="ravenphpscripts.com">RPS </a>"; |
Just escape the quotes;
Code:echo "<a href =\"ravenphpscripts.com\">RPS </a>";
|
|
|
|
|
 |
testy1

|
Posted:
Fri Sep 19, 2008 4:48 am |
|
you dont actually need double quotes for compliance but it is pretty much a standard rule.
i prefer to do it as follows
Code:
echo '<a href="ravenphpscripts.com">RPS</a>' . "\n";
|
but it's personal preference really.
but I think we are way off topic now  |
|
|
|
 |
montego

|
Posted:
Fri Sep 19, 2008 5:49 am |
|
Yup... that is how I do it as well. Only thing I wanted to add, is that I have moved away from even using the . "\n" as it is just extra characters to type and with the good extensions these days for FF and other browsers, you can with a click of the button, have your HTML reformatted for easier reading if you really need it. |
|
|
|
 |
Gremmie

|
Posted:
Fri Sep 19, 2008 7:15 am |
|
Raven wrote: | XHTML standards compliance requires that all attributes be in double quotes |
This is not true. Single quotes are accepted by the spec. Perhaps you are thinking of the rule that says that all attributes must be quoted, unlike HTML. The choice of the quote is up to you. If only double quotes were allowed you could not have an attribute that contained a double quote character. |
|
|
|
 |
djmaze
Subject Matter Expert

Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv
|
Posted:
Fri Sep 19, 2008 12:26 pm |
|
XHTML speaking: you're not allowed to use entities. So £ is NOT, i repeat, IS NOT the solution!
Get a hang of charset usage and UTF-8 |
|
|
|
 |
Raven

|
Posted:
Fri Sep 19, 2008 12:39 pm |
|
I stand corrected. The best practices suggest to always use double quotes for attributes unless you need to have a double quote in the value pair. Otherwise you should use double quotes. |
|
|
|
 |
Gremmie

|
Posted:
Fri Sep 19, 2008 12:41 pm |
|
djmaze, I'm curious about that, and have read conflicting things. I have used entities such as • and € in pages and they have been accepted by the online W3 validator.
See this from the spec: http://www.w3.org/TR/xhtml1/#h-A2
Edit: so from the above, I believe named entities are allowed in XHTML. |
|
|
|
 |
|