Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-26-2012, 11:27 PM   PM User | #1
jasonmwhitaker
New Coder

 
Join Date: Nov 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
jasonmwhitaker is an unknown quantity at this point
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.
jasonmwhitaker is offline   Reply With Quote
Old 04-27-2012, 07:24 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,907
Thanks: 10
Thanked 293 Times in 289 Posts
Dormilich is on a distinguished road
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.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Users who have thanked Dormilich for this post:
jasonmwhitaker (04-27-2012)
Old 04-27-2012, 03:17 PM   PM User | #3
jasonmwhitaker
New Coder

 
Join Date: Nov 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
jasonmwhitaker is an unknown quantity at this point
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
jasonmwhitaker is offline   Reply With Quote
Reply

Bookmarks

Tags
echo, javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:18 AM.


Advertisement
Log in to turn off these ads.