Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/233771-parse-error-when-inserting-code/
Share on other sites

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?

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'));

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\'));

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\'));

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.