Author |
Message |
killing-hours
RavenNuke(tm) Development Team
![](modules/Forums/images/avatars/18f54b284d120ece8c103.gif)
Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx
|
Posted:
Fri Apr 08, 2011 7:37 am |
|
Hey all-
I'm helping with a project and the coding methods that are used raise a few questions for me. Some feedback is appreciated.
1. PHP_EOL
I understand that PHP_EOL is used to get a new line.... but is it necessary?
Example:
Code:echo '<script type="text/javascript">//<![CDATA['.PHP_EOL;
echo ' $("button").click(function () {'.PHP_EOL;
echo ' $("#post-comment").show("slow");'.PHP_EOL;
echo ' });'.PHP_EOL;
echo '//]]></script>'.PHP_EOL;
|
Is it necessary to have this at the end of each output line? I've written a couple of other applications but didn't use newline's and it seems my applications run fine... but now I'm worried they aren't correct.
Here are some comments I've read: http://stackoverflow.com/questions/128560/when-do-i-use-the-php-constant-php-eol
2. CDATA
Using the above code as an example... what is the purpose of have the CDATA markers? If I'm reading this correctly, HTML parsers (reading "browsers"???) don't understand them anyhow.
wikipedia wrote: | Since it is useful to be able to use less-than signs (<) and ampersands (&) in web page scripts, and to a lesser extent styles, without having to remember to escape them, it is common to use CDATA markers around the text of inline <script> and <style> elements in XHTML documents. But so that the document can also be parsed by HTML parsers, which do not recognise the CDATA markers, the CDATA markers are usually commented-out |
https://secure.wikimedia.org/wikipedia/en/wiki/CDATA\
Thanks for your time. |
_________________ Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
fkelly
Former Moderator in Good Standing
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Fri Apr 08, 2011 8:08 am |
|
Good questions and I will be interested in the answer(s) to the cdata one myself. Re. PHP_EOL I think that's similar to or identical with "\n" that we see in the RN code a lot. In my experience where it is useful is if you have to review output using view source. Let's say you have a lot of options in a select list, for example state abbreviations. It's a lot easier to look through the generated code for errors if they are all on separate lines rather than just strung out on a long single line. And, unfortunately, there are a lot of times when you will need to use view source to confirm what's being output or to debug. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
spasticdonkey
RavenNuke(tm) Development Team
![](modules/Forums/images/avatars/48fb116845dfecf66294c.gif)
Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Fri Apr 08, 2011 8:36 am |
|
I think it's a coders choice, it's kinda nice to have easy to read code that is output to the browser. I like PHP_EOL as it's a little cleaner in the code than the alternative
'.PHP_EOL;
or
'."\n";
I suppose it does offer some cross platform compatibility but I would never recommend running on a windows server anyway, so... that's somewhat a wash. You can see pretty much what is does in the Content module
modules/Content/var/cpfunc.php
Code:if(!defined('PHP_EOL')) define ('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
|
As for CDATA, to the best of my understanding it's only used on inline JS so that the contents are not parsed as html, and usually wrapped in comments for older browsers that don't understand CDATA. If the browser does properly understand CDATA, it keeps you from having to escape certain characters to pass validation. Although, someone may have a better explanation ![Rolling Eyes](modules/Forums/images/smiles/icon_rolleyes.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
killing-hours
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 08, 2011 8:48 am |
|
@fkelly's response...
PHP_EOL = "\n" or better "r\n\" (From what I gather in the comments from stackoverflow)
The reason I ask for it's purpose and in all reality... when it "should" be used... is for size sake. The script should be a small as possible and it seems to me that if the PHP_EOL or "\n" is overused... it's going to add unnecessary size to the script itself thus slowing the load time down. (although it may only be very minute)
@ CDATA ... if used in inline JS.. since RN uses the "addJsToHead" function to pass the inline to the head when it is loaded in in the browser... wouldn't that relegate the CDATA pointless. Also very interested in further discussion on this one.
Edit*** I could see the point of CDATA in the case that JS was used on a particular input or link or something where the inline is directly on the html and not run through the addJsToHead function.
Thanks for the responses guys. Helps me to understand things a bit better. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
fkelly
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 08, 2011 9:27 am |
|
Quote: | The reason I ask for it's purpose and in all reality... when it "should" be used... is for size sake. The script should be a small as possible and it seems to me that if the PHP_EOL or "\n" is overused... it's going to add unnecessary size to the script itself thus slowing the load time down. (although it may only be very minute) |
If diagnosing a problem is a little bit easier (and thus quicker) for the programmer because the output is more readable it will more than make up for any inefficiencies having a few extra "r\n"s in the code cost. There are many other things we can do to make the code efficient without rendering the output humanly unreadable, IMHO. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
killing-hours
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 08, 2011 9:34 am |
|
Agreed. I don't however debug that way so in my instance it doesn't really matter I don't believe.
So I'm save to assume that it's not necessary for the server itself to see that next line character (unless say outputting data to a file of some sort) for compatibility etc. It's more or less for the ease of the programmer and debugging purposes or human readability... correct? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|