apostrophes and all that jazz...

Discussion in 'PHP' started by abcdefGARY, Sep 16, 2006.

  1. #1
    I am kind of stumped here...

    I'm trying to change this into php friendly code:
    			<a href="#"
    				onmouseover="changeImages('image_button1', 'images/image_button1-over.gif'); return true;"
    				onmouseout="changeImages('image_button1', 'images/image_button1.gif'); return true;">
    Code (markup):
    and this is what I came up with... works in Firefox, but in IE, it says that there is an error. so I dont think IE can read the &apos; as an apostrophe...
    <?php
    echo"			<a href='$image' onmouseover='changeImages(&apos;image_button1&apos;, &apos;images/image_button1-over.gif&apos;); return true;' onmouseout='changeImages(&apos;image_button1&apos;, &apos;images/image_button1.gif&apos;); return true;'>";
    ?>
    Code (markup):
    does anyone have a solution? :eek:
     
    abcdefGARY, Sep 16, 2006 IP
  2. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    echo '<a href="'. $image .'" onmouseover="changeImages(\'image_button1\', \'images/image_button1-over.gif\'); return true;" [...]
    Code (markup):
     
    Icheb, Sep 16, 2006 IP
  3. abcdefGARY

    abcdefGARY Well-Known Member

    Messages:
    665
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    thanks ill give this a try when i get home
     
    abcdefGARY, Sep 16, 2006 IP
  4. abcdefGARY

    abcdefGARY Well-Known Member

    Messages:
    665
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #4
    hmm, doesn't work...

    if I change echo"......" to echo '.....'

    it doesn't work for some reason...
     
    abcdefGARY, Sep 17, 2006 IP
  5. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php
    echo "<a href=\"$image\" onmouseover=\"changeImages('image_button1', 'images/image_button1-over.gif'); return true;\" \n onmouseout=\"changeImages('image_button', 'images/image_button1.gif'); return true;\">";?>
    PHP:
    test:
     
    vdd, Sep 17, 2006 IP
    abcdefGARY likes this.
  6. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    My code is perfectly fine. Using single quotes instead of double quotes should always be the way to go. Now if you bothered to post an error message I could have helped you, but I'm afraid I can't read your mind yet.
     
    Icheb, Sep 17, 2006 IP
  7. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Icheb, double quotes work faster then single quotes.
     
    vdd, Sep 17, 2006 IP
  8. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Of course not. You cannot change from single to double quotes and expect PHP to behave the same. Programs such as Perl and PHP consider single and double quotes differently. Material between single quotes is treated literally. This allows you to place special characters within the string without needing to escape the special characters with a backslash.

    A fair explanation is at the PHP site: http://ca.php.net/types.string

    A bit of a tutorial on the subject is located here: http://www.astahost.com/info.php/php-interpolation_t4286.html

    In terms of whether or not single or double quotes are faster . . . it seems the answer depends. Material between single quaotes is not processed for the presence of variables, whereas double quoted strings may contain variables. In certain situations, single quotes result in speed gains. But, there are probably more significant optimizations which you can make.

    A good article on optimization is located here: http://phplens.com/lens/php-book/optimizing-debugging-php.php
     
    clancey, Sep 17, 2006 IP
  9. abcdefGARY

    abcdefGARY Well-Known Member

    Messages:
    665
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #9
    thank you. this works perfectly. ill add some green.

    sorry, there wasn't any error message... the onmouseover just didn't work and IE kept displaying that there was an error with the page on the status bar.
     
    abcdefGARY, Sep 17, 2006 IP
  10. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Stop talking trash, it's the other way round.

    If you use single and double quotes exactly the way I showed you, it will work.
     
    Icheb, Sep 17, 2006 IP
  11. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Icheb's code works.
     
    vdd, Sep 17, 2006 IP
  12. Mrblogs

    Mrblogs Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    or (to remove the horrid use of back-slashes):

    <?php
    echo <<<EOF
    <a href="#" onmouseover="changeImages('image_button1', 'images/image_button1-over.gif'); return true;"				onmouseout="changeImages('image_button1', 'images/image_button1.gif'); return true;">
    EOF;
    ?>
    
    Code (markup):
     
    Mrblogs, Sep 18, 2006 IP