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

[SOLVED] preload_replace variable not working correctly.

Development and Programming

MrBaseball34's avatar
MrBaseball34
99 posts
14 years ago
MrBaseball34's avatar MrBaseball34

got a template with this preload_replace:

{preload_replace:file_dir="http://mysite.com/directory.php?file_dir=/files/"}

And called like this in my template:

<?php
  echo file_get_contents({file_dir});
?>

However, I get this error:

Parse error: syntax error, unexpected ':' in expressionengine/libraries/Functions.php(640) : eval()'d code...

How do I fix this? I have my template preferences set to Allow PHP and PHP Parsing Stage= Output.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
14 years ago
Mark Bowen's avatar Mark Bowen

What exactly is that URL and what does it return if you just visit it by itself in a browser?

I just tested this code :

{preload_replace:my_variable="http://www.google.com"}


<?php
    $homepage = file_get_contents('{my_variable}');
    echo $homepage;
?>

and it all seemed to work fine so I’m just wondering if it’s perhaps something to do with what you’re trying to feed into the variable maybe?

Best wishes,

Mark

       
MrBaseball34's avatar
MrBaseball34
99 posts
14 years ago
MrBaseball34's avatar MrBaseball34

If I use the url

http://mysite.com/directory.php?file_dir=/files/

in the browser, it returns the exact html I want to show.

If I modify the directory script back to it’s original code that had the path to opendir() hardcoded to ‘/files/’ , then this works exactly as planned:

<?php
  echo file_get_contents("http://mysite.com/directory.php");
?>
       
icebreaker's avatar
icebreaker
50 posts
14 years ago
icebreaker's avatar icebreaker

There’s a couple of single quotes around {my_variable} in the example that worked.

       
MrBaseball34's avatar
MrBaseball34
99 posts
14 years ago
MrBaseball34's avatar MrBaseball34

That was it, thanks a lot.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
14 years ago
Mark Bowen's avatar Mark Bowen
That was it, thanks a lot.

Oops sorry had meant to point that out in my post above, sorry.

Glad that’s working for you now though.

Best wishes,

Mark

       

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.