PHP Web Host - Quality Web Hosting For All PHP Applications Sign up for PayPal and start accepting credit card payments instantly
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
wiz
Client


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

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

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 Back to top

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
Client


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

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

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
View user's profile Send private message Visit poster's website AIM Address
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 Back to top

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.
View user's profile Send private message
warren-the-ape
Worker
Worker


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

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

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


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

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

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>";
View user's profile Send private message Visit poster's website AIM Address
Gremmie
Former Moderator in Good Standing


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

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

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


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

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

So a , is faster than a .?
View user's profile Send private message Visit poster's website AIM Address
Gremmie
Former Moderator in Good Standing


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

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

Apparently, according to one of the Zend developers.
View user's profile Send private message
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6373
Location: Vsetin, Czech Republic

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

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 Visit poster's website
montego
Site Admin


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

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

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.
View user's profile Send private message Visit poster's website
Gremmie
Former Moderator in Good Standing


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

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

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


Joined: Apr 06, 2008
Posts: 483

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

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 to the forums!


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
Former Moderator in Good Standing


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

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

Test in a loop. That file is only testing double quote concatenation, unless you changed it between runs.
View user's profile Send private message
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

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

yes i changed it between runs, how would i test it via a loop
View user's profile Send private message
Gremmie
Former Moderator in Good Standing


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

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

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.
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

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 Visit poster's website AIM Address Yahoo Messenger
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

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

somebodies always got to wreck the party Razz
View user's profile Send private message
warren-the-ape
Worker
Worker


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

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

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>";
View user's profile Send private message
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

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

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


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

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

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.
View user's profile Send private message Visit poster's website
Gremmie
Former Moderator in Good Standing


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

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

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.
View user's profile Send private message
djmaze
Subject Matter Expert


Joined: May 15, 2004
Posts: 689
Location: http://tinyurl.com/5z8dmv

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

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
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

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.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Gremmie
Former Moderator in Good Standing


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

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

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 to the forums!


Edit: so from the above, I believe named entities are allowed in XHTML.
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum