0

Here is my code:

$buffer .= '<legend>'.$thisField.'</legend><input type="text" name="'.$thisField.'" id="'.$thisField.'"/> <a href="javascript:;" onClick="mcImageManager.browse({fields : 'url_abs'});">[Pick file]</a><br /><small>360px W x 240px H</small><br /><br />';

It is breaking syntax error, unexpected T_STRING

I have tried every type of combination of single quotes, double quotes and escaping ??

I am at a loss, What am I missing??

Thanks!!

4 Answers 4

3

Just escape your quotes inside the string with a backslash:

$buffer .= '<legend>'.$thisField.'</legend><input type="text" name="'.$thisField.'" id="'.$thisField.'"/> <a href="javascript:;" onClick="mcImageManager.browse({fields : \'url_abs\'});">[Pick file]</a><br /><small>360px W x 240px H</small><br /><br />';

See the PHP manual:

To specify a literal single quote, escape it with a backslash (\).

Sign up to request clarification or add additional context in comments.

Comments

2

In such cases it's advisable to resort to HEREDOC strings, also for readability:

$buffer .= <<<END
  <legend>$thisField</legend>
  <input type="text" name="$thisField" id="$thisField"/>
  <a href="javascript:;" onClick="mcImageManager.browse({fields : 'url_abs'});">[Pick file]</a>
  <br /><small>360px W x 240px H</small><br /><br />
END;

This avoids having to escape any quotes. And you can just write $variables as-is within such a block.

1 Comment

To be honest, I think this is approaching the point where it's advisable to use genuine templates, but HEREDOC is a good suggestion nonetheless.
1

As the highlighter tells you, php will fail near {fields : 'url_abs'}. You're inside a single quoted string, so you'll have to escape the single quotes inside the string: {fields : \'url_abs\'},

Comments

0

The issue is the single quotes around url_abs.

Comments

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.