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

Inserting EE tags into PHP? The brace of EE tag is breaking the PHP expression...

Development and Programming

DavidB's avatar
DavidB
11 posts
15 years ago
DavidB's avatar DavidB

I want to call an EE tag within PHP but am getting an error because PHP doesn’t like the { of the EE tag. I’m simply trying to call an integer from a channel entry then add 15 to it - this is what I have:

height="<?php
    $height = {video_file_height} + 15;
    echo "$height"; ?>"

I have PHP enabled to parse at output (I have tried at input, too).

Any suggestions from PHP experts more than welcome!

       
cherrypj's avatar
cherrypj
158 posts
15 years ago
cherrypj's avatar cherrypj

EE tags are not really PHP. Well, they are, but not straight PHP, so you’ll want to escape the EE output. Try:

height="<?php
  $height = "{video_file_height}" + 15;
  echo "$height"; ?>"
       
DavidB's avatar
DavidB
11 posts
15 years ago
DavidB's avatar DavidB

Just tried putting the quote marks in. It prevents the code from throwing an error, but it just outputs 15, rather than adding two figures together. My guess is that the quotes mean the PHP treats the EE value as a string rather than an integer and doesn’t add it to the sum. Could this be right? And, if so, is there a workaround?

       
cherrypj's avatar
cherrypj
158 posts
15 years ago
cherrypj's avatar cherrypj

You can try intval:

height="<?php
  $height = intval('{video_file_height}') + 15;
  echo "$height"; ?>"

Works for me if PHP is parsed on output.

       
DavidB's avatar
DavidB
11 posts
15 years ago
DavidB's avatar DavidB

Yes, that works. Thank you so much for your help, Michael!

       
cherrypj's avatar
cherrypj
158 posts
15 years ago
cherrypj's avatar cherrypj

Oh, good! Glad to get you sorted.

       

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.