Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Echoing JavaScript / Problems with Quotation Marks vs. Apostrophes

    Hello, everyone. I'm trying to move a lot of content that was embedded into a CMS into a functions file that ties into hooks. Everything's going pretty good except for my attempt at getting the below function to work.

    Essentially, It's inserting an area with some social networking buttons. The Pinterest button uses JavaScript and my quotation marks are causing problems. I tried escaping, I tried switching to apostrophes, etc... and was able to get some things to work and others not.

    Below is an echo with the raw HTML code without any of the things I've tried so you have a clear picture:

    Code:
    echo '<br /><div style="float:left;clear:left;height:35px;width:60px;"><a href="javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());"><img class="aligncenter" src="http://www.mysite.com/wp-content/uploads/2011/09/pinit.jpg" alt="Pin It" /></a></div><div style="float:left;clear:right;"><iframe src="//www.facebook.com/plugins/like.php?href='.the_permalink().'&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:35px;" allowTransparency="true"></iframe></div><br /><br /></div>';
    Just in case you're wondering, the error does not lie directly with the '.the_permalink.' part of the script as I did try removing that.

    So can anyone tell me what to replace with apostrophes, what to escape with a backslash, etc...?

    I really appreciate the help.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,335
    Thanks
    13
    Thanked 348 Times in 344 Posts
    IMHO one of the simplest solutions to the quotation mess (you have JS in HTML in PHP) would be separating languages. you can set the JS code in an external file, same goes for CSS, which leaves you with just HTML.

    for a quick 'n' dirty fix you can use the HEREDOC syntax.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    jasonmwhitaker (04-27-2012)

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks! Ultimately, I removed the inline CSS and added classes and managed the styles from the main stylesheet. I also removed the JavaScript and placed it in a separate function that loaded in the footer, and instead called the function from the HREF.

    I appreciate the advice!

    Jason


  •  

    Tags for this Thread

    Posting Permissions

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