Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Array to html table

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Eight spaces per level?
    No, tabs.


    Code:
    <td onclick='alert(\"Hello!  How\\'re you?\");'>
    The slash would escape the other slash--
    Code:
    <td onclick='alert(\"Hello!  How\\\'re you?\");'>
    Personally, I find using dots to be just fine.
    echo 'something'.$var.'something';
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    No, tabs.
    Ah, vB converted them to eight spaces each.
    The slash would escape the other slash--
    It was meant to (that was the double-quoted one, the single quote didn't need to be escaped for PHP).
    Personally, I find using dots to be just fine.
    echo 'something'.$var.'something';
    But it's still ugly (as seen in the single-quoted example) and mixes presentation with logic, which is A Bad Thing.
    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!

  3. #13
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I think it makes perfect sense.

    echo $var1.'text1'.$var2.'text2';

    It's not very complex logic, certainly. Could be very overwhelming if you had lots of operations in there, but just a single variable seems reasonable.

    In fact, it's less to figure out than breaking out of PHP, I'd say.


    As for the slash, ah, yes. But... it isn't needed, then. You either have one or three, as the two will cancel each other out, rendering the effect null.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    Again, yes, for a little data on a single line (and I've done it: see the <?php echo ... ?> bit?). However, you're probably storing HTML (output/presentation data) in the logic section of the program if you find yourself doing this (or vice versa, if you have a long echo statement in the middle of a chunk of HTML).
    In fact, it's less to figure out than breaking out of PHP, I'd say.
    Again, a template system would be preferable.
    As for the slash, ah, yes. But... it isn't needed, then. You either have one or three, as the two will cancel each other out, rendering the effect null.
    No. A single backslash escapes the character after it, although PHP will usually just render the slash if the next character doesn't make any sense when escaped. You seem to be misunderstanding the code a little here: let's break it down a little.
    • In our PHP code, we have two backslashes and an apostrophe: \\'
    • When this is parsed by PHP, the first backslash escapes the second, resulting in a single literal backslash, so it becomes \'
    • The single backslash then escapes the apostrophe for Javascript, so the final character is just a single apostrophe, '.
    And, it just goes to prove my point if even someone experienced with PHP can still get confused over what's escaping what
    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. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Haha. Hmmm... I was thinking about it backwards.
    However, you wouldn't need to escape the first slash in the first place there. That was my main point.
    Then I got it in my head that the escaping would hurt.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    However, you wouldn't need to escape the first slash in the first place there. That was my main point.
    Yes you would: just having \' will result in a literal apostrophe being sent to Javascript, with no backslash, and thus it would break.

    /EDIT: Actually, no, it's not necessary, at least in PHP5. However, that makes it a special case (one of the guesses I mentioned above) and so even less predictable and more confusing.
    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!

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "a\"a", 'a\'a', 'a"a', and "a'a" are correct from my experience.
    "a\'a" will output \', like 'a\"a'.

    It's been my impression that escaping only applies when a certain character has a use in that type of output (1. single quote, 2. double quote, 3. heredoc)

    1. just \' is needed, and \\ when you don't want to escape the ', like \\'.
    2. \t, \n, \[othercharacters], \", \$, and, again, \\.
    3. only \$ and \{, i'd assume. Never really played with it.

    So, if you had \' in single quotes, it wouldn't escape it as there is no point in escaping that ' for php. (For javascript, yes, but not within the php parsing).

    \\ escapes escaping, not a literal backslash. So it would only have an effect if it were escaping escaping, if the next character were to be parsed as something special aside from the \.

    In fact, it seems like it would be very important to check this, as javascript would receive \\', and escape it itself, though that doesn't seem to be an issue. Odd.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    Yes. But, that's inconsistent behaviour (as demonstrated by the fact that it took you two paragraphs to explain it ).
    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!

  9. #19
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Did you notice my edit? I just updated the post to make more sense. Plus, something went wrong with the first post and cut off a bit.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    I think you're trying to say that \\ isn't a literal backslash. If you are, you're wrong
    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
  •