最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论