single quote parse error ?
Posted: 29 August 2008 08:15 AM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  104
Joined  05-31-2005

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!

Profile
 
 
Posted: 29 August 2008 08:34 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12433
Joined  04-29-2002

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

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 29 August 2008 09:02 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  104
Joined  05-31-2005

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

Profile
 
 
Posted: 29 August 2008 12:03 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

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?

 Signature 
Profile
MSG
 
 
Posted: 29 August 2008 04:36 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  104
Joined  05-31-2005

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

Profile
 
 
Posted: 29 August 2008 04:50 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

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

 Signature 
Profile
MSG
 
 
Posted: 29 August 2008 06:14 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  326
Joined  03-18-2007

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

Profile
 
 
Posted: 30 August 2008 04:08 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  104
Joined  05-31-2005

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

Matt, that did it. Thanks!

Profile
 
 
Posted: 30 August 2008 10:27 AM   [ Ignore ]   [ # 8 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15869
Joined  06-03-2002

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();
?>

 Signature 
Profile
MSG
 
 
Posted: 30 August 2008 11:12 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  326
Joined  03-18-2007

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

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65085 Total Logged-in Users: 34
Total Topics: 82222 Total Anonymous Users: 17
Total Replies: 441913 Total Guests: 221
Total Posts: 524135    
Members ( View Memberlist )
Newest Members:  BombermanhaimtuagocsadamVeNeaDoRHildegaardhrtrulzUNFORGIVEN IIIEmmanuelYanYanTomsB