Twitist Forums
Integrating FBML and PHP in my facebook app? - Printable Version

+- Twitist Forums (http://twitist.com)
+-- Forum: Facebook forums (/forum-14.html)
+--- Forum: Facebook apps (/forum-22.html)
+--- Thread: Integrating FBML and PHP in my facebook app? (/thread-99606.html)



Integrating FBML and PHP in my facebook app? - Katie - 02-19-2014 12:41 PM

I'm trying to use blocks of fbml and blocks of php in my facebook application. However, I am trying to use my php variables in the fbml and it's not working.

For example I want to use the fb:time and use a variable created in my php block above it called $start. But it won't let me because its not an "integer".

for example I have something like

<?php
$start = 1235298413; //this number will change from queries to DB
?>

<fb:time t=$start tz="America/New_York" />

Can someone help please? I want to display this time.


- SkaNinja - 02-19-2014 12:42 PM

There are a few problems. First, you need quotes around your number. That's less important, because since $start is outside of PHP scope, it's being parsed just like regular HTML, which doesn't recognize $start, of course. There are a number of ways to do this.

1) Add PHP scope around your variable:

<fb:time t="<?= $start ?>" tz="America/New_York" />

2) Extend your overall scope to include the HTML code, but output it through PHP:

<?php
$start = 23434;

echo "<fb:time t=\"$start\" tz=\"America/New_York\" />";

OR

echo '<fb:time t="'.$start.'" tz="America/New_York" />';
?>

This is pretty simple PHP knowledge, so I'm under assumption you don't know PHP very well. I'd suggest that trying to make a Facebook app is not the best way to learn.