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!

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

 

It just winds up storing this in the variable:

 

<script>setTimeout( function() , 30000);</script>

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.