Results 1 to 9 of 9

Thread: Distinguishing One Language from the Next

  1. #1
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default Distinguishing One Language from the Next

    Quote Originally Posted by kuau View Post
    PS. To someone who is new to all this, can someone please explain how the edges of things are determined? Where does php end and url escaping start? Isn't url escaping part of php? How does one tell when an html phrase suddenly turns into javascript? or is that php? or sql? or maybe css? or xml? To the uninitiated it is all one big jumbled melee and I am never quite sure where to post my questions.
    I think this is a very good question, so I'm going to take a shot at answering it. I invite others to contribute as well.

    The Web is modular, having separate interdependent parts. A module is any certain type of program, and there's a hierarchy (e.g., a browser is a type of client). These modules typically communicate with each other via strings (character sequences) which conform to patterns (data languages) understood by all involved programs. The later modules naturally build on the earlier ones, and the most basic module could be called the "core."

    URLs are a data language very close to the core; every module must deal with them in one way or another. A browser/client uses them to request resources from servers (and the local filesystem); a server-side scripting language like PHP uses them to 1) request resources from either its local server or a remote server, and 2) tell the browser what resources to request.

    Quote Originally Posted by kuau View Post
    Isn't url escaping part of php?
    Sort of; it's just a responsibility that PHP, along with ASP, Java, and almost any other programming language, must perform occasionally. Such a question should be posted in the forum of the language that needs to escape the URL.

    Quote Originally Posted by kuau View Post
    How does one tell when an html phrase suddenly turns into javascript?
    I can think of 3 kinds of situations like this. (By the way, all of these are considered bad practice, mostly in favor of separating behavior and structure.)
    • An inline script. This can be in the head, body, almost anywhere. I thought about listing the linked script, but that doesn't put JS alongside HTML.
      Code:
      <script type="text/javascript">alert('This is HTML-embedded JavaScript.');</script>
    • An event handler. As JS alongside HTML, this is always a tag attribute that begins with on.
      Code:
      <button value="Do something!!" onclick="doSomething();">Do something!!</button>
    • A URL with the javascript: protocol.
      Code:
      <form action="javascript:doSomething();">...</form>


    Quote Originally Posted by kuau View Post
    or is that php?
    Here's a simple example where PHP might get confused with JavaScript. This file is called js.php.
    Code:
    var example = <?php echo $example; ?>;
    Where you should post a question related to this would depend upon the question. Do you not understand how $example became the value it is? That's PHP. Maybe you need clarification of why it doesn't work or exactly what it means as JS? That's JS, but I suggest you post the JS code received by the browser rather than the unparsed PHP.

    Quote Originally Posted by kuau View Post
    or sql?
    SQL will normally only be in PHP/ASP/JSP or whatever server language you use. And then it will be in a string passed to a function that's obviously DB-related, like mysql_query.

    Quote Originally Posted by kuau View Post
    or maybe css?
    CSS is similar to JS in this respect; it will only be found in HTML in two special cases, but both of them are considered poor practice because style and structure get mixed:
    • The style tag.
      Code:
      <style type="text/css">
          body{
              height: 100%;
              width: 100%;
          }
      </style>
    • The style attribute.
      Code:
      <body style="height: 100%; width: 100%;"></body>


    But CSS and JS can also get jumbled. The first case is considered bad practice if you can put it in a stylesheet. The second case is a hack that only works in IE because Microsoft needed a way to let web-developers fix IE bugs, and I took the code from http://archivist.incutio.com/viewlist/css-discuss/44263.
    • Code:
      //This is JavaScript.
      document.getElementById('example').style.width = '100%';
    • Code:
      /*This is CSS.*/
      #container {
          width: expression((documentElement.clientWidth < 725) ? "725px" : "auto" );
      }


    Quote Originally Posted by kuau View Post
    or xml?
    I can think of two situations like this:
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  2. The Following User Says Thank You to Jesdisciple For This Useful Post:

    kuau (08-09-2008)

  3. #2
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear Chris: Thank you so much for the very thorough and enlightening answer to my question. I have a few more hours of homework to do on it, reading all the links and all, but I must say you broadened my understanding immensely. I am very much in favor of separating behavior and structure too (excellent article, which I wish all JS programmers would read and adopt). You even answered another question I had posted a while ago, that no one knew, about placing conditionals within the css file.

    One thing that puzzles me is the continual reference on the web to XHTML. Boogeyman once told me that XHTML had been abandoned as a bad idea, but it seems no one heard about that. Even the article about separating behavior and structure mentions it. Has XHTML been dropped?

    I'm not sure what you meant by this: (?)

    but I suggest you post the JS code received by the browser rather than the unparsed PHP
    XML and DOM is a bit beyond my brain at this time. Have to digest some of the rest first. Thanks so much for helping me learn. I love to be able to get my own code working and understand everything it is doing. An aspiration anyway.

    Mahalo, erin
    Last edited by kuau; 08-09-2008 at 09:54 PM. Reason: sp

  4. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    XHTML hasn't exactly been dropped. It's going to be continued in XHTML 5 (a reformulation of HTML 5 into XML) and then later on they will continue the original plans by finishing up XHTML 2.0 (confusing, eh).

    It is, however, currently unfeasible to use for most websites. See the link in my signature.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. The Following User Says Thank You to Twey For This Useful Post:

    kuau (08-09-2008)

  6. #4
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Erin, I've never been able to make that kind of post before, so I'm happy.

    Quote Originally Posted by kuau View Post
    I'm not sure what you meant by this: (?)
    Here's the example snippet I was using:
    Code:
    var example = <?php echo $example; ?>;
    Let's say $example is 5. After the PHP is parsed out of this by the server, this JavaScript will be sent to the browser:
    Code:
    var example = 5;
    If you want to find a bug in PHP-generated JS, you don't want to read and understand the PHP at the same time. To only post the JS as seen by the browser, 1) request the page with your own browser, 2) right-click the page and View Source (or however your browser phrases it), 3) find the script tag that has either inline JS or a src attribute, 4) send your browser to the URL in the src attribute if any, and 5) copy the JS into your post.

    That general process also works with HTML, CSS, XML, and anything else that might be generated on-the-fly by PHP.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  7. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm pretty sure this is just an issue with the differences between server-side and client-side scripting.

    This is the general flow of data:

    "js.php" > Parsed PHP (server-side) > HTML Output > Parsed Javascript (client-side)

    so js.php might be:

    Code:
    <script type="text/javascript"><?php
    $example = "example";
    ?>
    var example = "<?php echo $example; ?>";
    </script>
    and the output would be:

    Code:
    <script type="text/javascript">
    var example = "example";
    </script>
    - Mike

  8. #6
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear Twey: Excellent article on XHTML! Everything I ever wanted to know. I also checked your other links and had to tear myself away and get back to work. Homework for another day.

    One question I had a while back: Can you safely convert a file that is written with a doctype of XHTML transitional to strict HTML without losing any functionality? I would assume the answer is yes based on the article stating that very few XHTML pages are actually parsed by xml anyway, but how can you tell? I don't understand xml yet. Now when I see doctype XHTML transitional I figure the person used the default DreamWeaver setting and doesn't know that it is basically a non-entity. But if there are references to xml in the page, does it disable them? Maybe once I've read all your articles I won't need to ask this question. I wish I had the luxury of learning all the languages throroughly before having to maintain live sites, which just won't wait.

    Thanks, e

  9. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    OK you guys, I have to go repair my irrigation system before my banana trees all die from lack of water, so I'll read the rest of these after it's dark outside. Thanks for all the help! e

  10. #8
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Mike: Yes, the PHP stuff I listed above is like that. But I was trying to approach the issue from a broad perspective, illustrating where languages might blend and clarifying what seemed to need it. I consider the client-server relationship just one of the (more important) ways that modules interact.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  11. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    One question I had a while back: Can you safely convert a file that is written with a doctype of XHTML transitional to strict HTML without losing any functionality? I would assume the answer is yes based on the article stating that very few XHTML pages are actually parsed by xml anyway, but how can you tell?
    No. There are a couple of reasons for this. The first is that you're converting from transitional to strict, which means you lose a lot of stuff that shouldn't really be used and is only there for compatibility with HTML3, like <iframe>, <font>, the 'target' attribute, &c. The second is that XHTML does have features that HTML doesn't. If it's being sent as HTML then the browsers can't use them, but they are there, so it's not necessarily possible to convert entity-by-entity.
    I don't understand xml yet. Now when I see doctype XHTML transitional I figure the person used the default DreamWeaver setting and doesn't know that it is basically a non-entity. But if there are references to xml in the page, does it disable them?
    'References to XML'?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •