Jimmy058910 Posted April 15, 2011 Share Posted April 15, 2011 Hi, I tried putting this Viglink code into my custom themes index.template.php on my SMF forum (I should do that right?) and I ended up with this error... Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../Themes/androidrtk_rev4n/index.template.php on line 554 545: subMenusContainerId:\'admsubMenus\', 546: duration:\'150\' 547: }); 548: }); 549: } 550: </script> 551: 552: <script type="text/javascript"> 553: var vglnk = { api_url: '//api.viglink.com/api', 554: key: 'ad93febdf4e33c034d9635037b687fb3' }; 555: 556: (function(d, t) { 557: var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; 558: s.src = ('https:' == document.location.protocol ? vglnk.api_url : I figured since it was a copy paste code that it would work just fine :-\ In any case, how can I fix this? Thanks in advance, Jimmy Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/ Share on other sites More sharing options...
spiderwell Posted April 15, 2011 Share Posted April 15, 2011 i don't see the php code, just javascript? Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1201831 Share on other sites More sharing options...
Jimmy058910 Posted April 15, 2011 Author Share Posted April 15, 2011 I know that copy/paste code is Javascript, but I thought this was a php error on a php file. Sorry if I shouldnt have posted this here Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1201910 Share on other sites More sharing options...
spiderwell Posted April 15, 2011 Share Posted April 15, 2011 the error is reporting a php error, but i can't see any php as you only posted up javascript, this is why I am confused. is this the 'raw' php file or the output of the php? Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1201963 Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 seems to be missing the "http:" at the start of the api_url declaration... Probably nothing to do with it, but I know even less about JS than I do PHP Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1201967 Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 The first few lines of the code you posted have the single quites escaped: 545: subMenusContainerId:\'admsubMenus\', 546: duration:\'150\' Which might be because the JavaScript is inside a PHP string. If you escape the other single quotes like this: subMenusContainerId:\'admsubMenus\', duration:\'150\' }); }); } </script> <script type="text/javascript"> var vglnk = { api_url: \'//api.viglink.com/api\', key: \'ad93febdf4e33c034d9635037b687fb3\' }; (function(d, t) { var s = d.createElement(t); s.type =\ 'text/javascript\'; s.async = true; s.src = (\'https:\' == document.location.protocol ? vglnk.api_url : Dose it fix the error? Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1201968 Share on other sites More sharing options...
Jimmy058910 Posted April 15, 2011 Author Share Posted April 15, 2011 It doesn't fix the error, but it changes it to this: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../Themes/androidrtk_rev4n/index.template.php on line 556 547: }); 548: }); 549: } 550: </script> 551: 552: <script type="text/javascript"> 553: var vglnk = { api_url: \'//api.viglink.com/api\', 554: key: \'ad93febdf4e33c034d9635037b687fb3\' }; 555: (function(d, t) { 556: var s = d.createElement(t); s.type =\ 'text/javascript'; s.async = true; 557: s.src = (\'https:\' == document.location.protocol ? vglnk.api_url : 558: '//cdn.viglink.com/api') + '/vglnk.js'; 559: var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); 560: }(document, 'script')); Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1202090 Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 556: var s = d.createElement(t); s.type =\ 'text/javascript'; s.async = true; The single quote after javascript needs to be escaped as well as the others. Try: 556: var s = d.createElement(t); s.type =\ 'text/javascript\'; s.async = true; 557: s.src = (\'https:\' == document.location.protocol ? vglnk.api_url : 558: \'//cdn.viglink.com/api\') + \'/vglnk.js\'; 559: var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); 560: }(document, \'script\')); Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1202092 Share on other sites More sharing options...
analog Posted April 15, 2011 Share Posted April 15, 2011 whoops there was a space between the backslash and single quote near text/javascript. Try: 556: var s = d.createElement(t); s.type = \'text/javascript\'; s.async = true; 557: s.src = (\'https:\' == document.location.protocol ? vglnk.api_url : 558: \'//cdn.viglink.com/api\') + \'/vglnk.js\'; 559: var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); 560: }(document, \'script\')); Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1202099 Share on other sites More sharing options...
Jimmy058910 Posted April 15, 2011 Author Share Posted April 15, 2011 It worked. Thanks a ton for the help! Quote Link to comment https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/#findComment-1202101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.