We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

single quote parse error ?

Development and Programming

avroo's avatar
avroo
164 posts
16 years ago
avroo's avatar avroo

hm, I am passing a custom field to php variable like this:

<?php

$body = '{body}';

?>

Problem: when the body has single quotes (‘) in it, it cannot be parsed (eval() parsing error in core.functions.php)

I already tried this one, but it doesn’t solve the problem:

<?php

$myVar = <<< EOD

{my_ee_var}

EOD;
?>

anyone got an idea?

TIA!

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
16 years ago
Sue Crocker's avatar Sue Crocker

avroo, is there a reason why you don’t use double quotes instead?

       
avroo's avatar
avroo
164 posts
16 years ago
avroo's avatar avroo

nope, I tried both single and double…both result in a parse error…

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
16 years ago
Lisa Wess's avatar Lisa Wess

Yes, nesting quotes is going to cause you problems; you’ll need to do some sanitization on the data so that you don’t run into this. You might consider moving this into a plugin so that you can work with it more comprehensively.

In any case, this is beyond what we can offer as technical support - did you want me to move it to the Plugins forum (if you’re going to go that route) or How To?

       
avroo's avatar
avroo
164 posts
16 years ago
avroo's avatar avroo

ok, clear. Then I am going to try to build a plugin, thanks!

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
16 years ago
Lisa Wess's avatar Lisa Wess

Awesome, avroo. I’ve moved this for you. =)

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

I’ve used the heredoc with quotes successfully before without issue. That “should” work…

What happens if you put the closing PHP tag on the next line, after the EOD; (there should be nothing else except “EOD;” on that line, not even extra whitespace)?

-Matt

       
avroo's avatar
avroo
164 posts
16 years ago
avroo's avatar avroo

And again, too much time wasted of my life caused by some damn ENTER.

Matt, that did it. Thanks!

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

You could also use output buffering instead of HEREDOC, which will prevent PHP from attempting to parse variables. Consider the content:

I made $15 selling peanuts!

If you put that into a HEREDOC without escaping the dollar sign, you’ll get an unexpected $end syntax error. Output buffering, however, doesn’t parse anything.

<?php ob_start(); ?>
{example_variable}
<?php
$str = ob_get_contents();
ob_end_clean();
?>
       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

Great tip! Makes sense now why the plugin docs use that. Thanks Derek.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.