page include within php function

I’m trying to include a page that contains html plus a web form into this php function. I’m sure you’ll be able to easily spot my failed attempt to include it. the optin.php page.

[php]
function get_video($postID) {
if( function_exists(‘p75GetVideo’) ) {
$video = p75GetVideo($postID);
$optin = “optin.php”;
return $video ? “

” . $video . “” . $optin . “
” : “”;
}
return “”;
}
[/php]

Any help is greatly appreciated.

That method will just output the string “optin.php”

You need to use:
[php]include ‘optin.php’;[/php]

Thanks so much for your help. Is this how you mean?:

[php]
function get_video($postID) {
if( function_exists(‘p75GetVideo’) ) {
$video = p75GetVideo($postID);
$optin = include ‘optin.php’;
return $video ? “

” . $video . “” . $optin . “
” : “”;
}
return “”;
}
[/php]

The result I see is it’s placing the contents of optin.php above the $video. The result I’m after is to contain $optin within the id=‘video’ and id=‘video-inside’ div tags. $video is to float left and $optin float right so they’re both inline. Not sure if you’re willing to take a look but here’s where I’m at with the function above: http://design3.redhenwebdesign.com/calling-all-rule-breakers/

Thanks!

I have rewritten your function for you:

[php]function get_video($postID) {
if( function_exists(‘p75GetVideo’) ) {
$video = p75GetVideo($postID);
if($video !=== false)
{
echo ‘

’;
echo $video;
include ‘optin.php’;
echo ‘
’;
return true;
}
else return ‘’;
}
return ‘’;
}[/php]

If you can’t echo at function call and are storing it in a variable however, you may need to use output buffering.

Okay, that is amazing. Like magic. Thanks Smokey PHP. I truly appreciate the assist on that.

Sponsor our Newsletter | Privacy Policy | Terms of Service