php - how to fix this unterminated string literal error? - Stack Overflow

It is giving me an unterminated string literal error: var image_file_name = "<br> for this

It is giving me an unterminated string literal error: var image_file_name = "<br/> for this line below:

var image_file_name = "<?php echo str_replace("\n", "", $image_file_name); ?>";

Any ideas on how this can fixed? Open to all ideas to test :)

It is giving me an unterminated string literal error: var image_file_name = "<br/> for this line below:

var image_file_name = "<?php echo str_replace("\n", "", $image_file_name); ?>";

Any ideas on how this can fixed? Open to all ideas to test :)

Share Improve this question asked May 11, 2012 at 17:56 user1394925user1394925 7529 gold badges29 silver badges51 bronze badges 2
  • 1 This is valid PHP code. The unterminated string literal is ing from something else. – drew010 Commented May 11, 2012 at 18:00
  • @user1384419 To elaborate since i can't edit the original ment, the unterminated string literal could be that you forgot to close a quote before the block of PHP code so the error shows on that line but in fact, the string could start many lines before where the error is showing. You can post more code, or see where you may have forgotten to close a ' or " above that line. – drew010 Commented May 11, 2012 at 18:17
Add a ment  | 

4 Answers 4

Reset to default 2

You're removing \n newlines but not \r carriage returns. Try removing both. It looks like IE (and possibly other browsers) also treats \r as a line break.

Perhaps:

str_replace(array("\n","\r"), "", $image_file_name)

(I'm assuming that $image_file_name contains Windows-style \r\n line breaks, not *nix-style \n line breaks.)

Try this:

var image_file_name = '<?php echo str_replace("\n", "", $image_file_name); ?>';

Trying to avoid the temptation to ask why you're assigning a php snippet to a JavaScript variable... :p

Please use it will solve the issues

 addcslashes($string, "\x00..\x1f\x22\x27\x5c")

What i usually do.

Create an input type hidden, fill his value with the php value and select it using a selector $("#hiddenData").val();

So you don't need to write the data in your script block using PHP. If you use a mvc framework it's a lot cleaner.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346417a4623566.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信