Jump to content

storing a string of javascript - dropping everything between { }


pachelbel101

Recommended Posts

Good evening,

 

How do you keep braces inside of a string?

 

I'm attempting to store a string of javascript into a variable.  That string of javascript contains braces, and everything between and including the braces is not showing up in the string.  I believe it's interpreting those braces as variable-enclosers, but they aren't.  I have tried escaping them (\{), doubling them ({{), putting them in single quotes instead of double quotes, and every time I lose everything between the braces. How do I keep braces inside of a string in PHP?

 

Thanks for your help, this is killing me!

Link to comment
Share on other sites

You have some mis-matched quote in the line:

<?php
$slideshowJavascriptCode = "<script>setTimeout( function() { window.location='".$config['baseurl']."/index.php"';}, 30000 );</script>";
?>

Try changing it to:

<?php
$slideshowJavascriptCode = '<script>setTimeout( function() { window.location="'.$config['baseurl'].'/index.php";}, 30000 );</script>';
?>

 

Ken

Link to comment
Share on other sites

Sorry, the quote wasn't wrong - I accidentally left it there when I removed some meaningless URL garbage off the end.

 

Also, I figured out a solution - if I wrap to the next line anywhere in the middle of the quote, then it doesn't try to interpolate the {}

 

Thanks for your help!

Link to comment
Share on other sites

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.