0

I am using some facebook post to wall JS, and the information for the post is echoed via php, but i get this error in the console:

SyntaxError: unterminated string literal    

description: 'Well, personal favorite in the following order.<br />

This is the row for the API call

description: '<?php echo $info['definition'] ?>'

and this is $info['definition'] string in the SQL database:

Well, personal favorite in the following order.

1. A stalkers dream come true

2. The reason most work are never done on time.

See what I mean with the examples.

If i use some other string, and type it in directly, it dosnt prompt the script error, how do i escape the string and make it work in the API call?

2
  • Any help here? Commented May 28, 2013 at 12:12
  • You have to remove all white spaces from the string Commented May 28, 2013 at 12:17

2 Answers 2

3

Try replacing the following line:

description: '<?php echo $info['definition'] ?>'

with this:

description: "<?php echo preg_replace( '~[\r\n]*~', '', $info['definition'] );?>"
Sign up to request clarification or add additional context in comments.

8 Comments

error changed to: description: "Well, personal favorite in the following order.&lt;br /&gt;
Can you please show what are you getting in your html. That would help in debugging. Can you post it to a fiddle so that we could test with it.
Dont really know how to pass the exact situation to a fiddle, considering the SQL, but i can give you the page of the error funkydictionary.com/words/?w=facebook%3D1#
Sorry, can you remove the ; from the end of the description node...i didn't know it was part of an object.
I removed the ; and the issue persists :(
|
0

You have to remove all white spaces from the string. Javascript considers all new lines as a new statement.

1 Comment

FYI white space would include the literal [space], so you don't want to remove whitespace, you want to remove line breaks...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.