Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
wiz
Involved
Involved



Joined: Oct 09, 2006
Posts: 413
Location: UK

PostPosted: Wed Sep 17, 2008 5:40 am Reply with quote

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
 
View user's profile Send private message Visit poster's website AIM Address
warren-the-ape
Worker
Worker



Joined: Nov 19, 2007
Posts: 196
Location: Netherlands

PostPosted: Wed Sep 17, 2008 5:59 am Reply with quote

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;

£ > &pound;
€ > &euro;

£322 > &pound;322
 
View user's profile Send private message
wiz







PostPosted: Wed Sep 17, 2008 6:08 am Reply with quote

ahhh got it Embarassed

Changed the £ to &pound 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 Smile

Cheers For that little oversight on my part
 
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Wed Sep 17, 2008 6:53 am Reply with quote

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.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
warren-the-ape







PostPosted: Wed Sep 17, 2008 7:16 am Reply with quote

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 Wink
 
wiz







PostPosted: Wed Sep 17, 2008 7:20 am Reply with quote

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







PostPosted: Wed Sep 17, 2008 3:29 pm Reply with quote

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. Smile I like cleanly separating business logic from presentation.
 
wiz







PostPosted: Wed Sep 17, 2008 5:05 pm Reply with quote

So a , is faster than a .?
 
Gremmie







PostPosted: Wed Sep 17, 2008 7:15 pm Reply with quote

Apparently, according to one of the Zend developers.
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Thu Sep 18, 2008 12:28 am Reply with quote

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.
 
View user's profile Send private message Send e-mail
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Thu Sep 18, 2008 6:05 am Reply with quote

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.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
Gremmie







PostPosted: Thu Sep 18, 2008 8:08 am Reply with quote

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
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Thu Sep 18, 2008 5:11 pm Reply with quote

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.....Click Here

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
 
View user's profile Send private message
Gremmie







PostPosted: Thu Sep 18, 2008 6:10 pm Reply with quote

Test in a loop. That file is only testing double quote concatenation, unless you changed it between runs.
 
testy1







PostPosted: Thu Sep 18, 2008 6:17 pm Reply with quote

yes i changed it between runs, how would i test it via a loop
 
Gremmie







PostPosted: Thu Sep 18, 2008 8:29 pm Reply with quote

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

PostPosted: Thu Sep 18, 2008 10:23 pm Reply with quote

All that aside Smile ....

XHTML standards compliance requires that all attributes be in double quotes, amongst other things. Wink
 
View user's profile Send private message
testy1







PostPosted: Thu Sep 18, 2008 10:40 pm Reply with quote

somebodies always got to wreck the party Razz
 
warren-the-ape







PostPosted: Fri Sep 19, 2008 1:25 am Reply with quote

Raven wrote:
XHTML standards compliance requires that all attributes be in (double) quotes, amongst other things. Wink


Wink


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







PostPosted: Fri Sep 19, 2008 4:48 am Reply with quote

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 Smile
 
montego







PostPosted: Fri Sep 19, 2008 5:49 am Reply with quote

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







PostPosted: Fri Sep 19, 2008 7:15 am Reply with quote

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

PostPosted: Fri Sep 19, 2008 12:26 pm Reply with quote

XHTML speaking: you're not allowed to use entities. So &pound; is NOT, i repeat, IS NOT the solution!

Get a hang of charset usage and UTF-8
 
View user's profile Send private message Visit poster's website
Raven







PostPosted: Fri Sep 19, 2008 12:39 pm Reply with quote

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







PostPosted: Fri Sep 19, 2008 12:41 pm Reply with quote

djmaze, I'm curious about that, and have read conflicting things. I have used entities such as &bull; and &euro; in pages and they have been accepted by the online W3 validator.

See this from the spec: [ Only registered users can see links on this board! Get registered or login! ]

Edit: so from the above, I believe named entities are allowed in XHTML.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©