CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Using php includes from within perl here document

 



tbone587
User

Nov 20, 2011, 1:30 PM

Post #1 of 5 (868 views)
Using php includes from within perl here document Can't Post

I have a website built using php includes and created a perl script that is editing files on the server. Within my perl script I am trying to have it output html to the browser with php includes, but the problem is its not interpreting the php code. When I view the source of the website instead of it showing the source within the php includes, it shows the actually commands. How do I make my subroutine below actually interpret the php?


Code
sub Html_ErrorOutput 
{

print "Content-type: text/html\n\n";
print <<HTML_ERROR

<?php include("includes/navigation.php"); ?>
<div id="content-wrap" >
<!-- |||||||||||||||||||||||||||||||||||||||Website content begins here|||||||||||||||||||||||||||||||||||||||||||||| -->
<div id="contentheader">Change Phone Display</div>
<div id="maincontent">

$HtmlError

<br/>

</div>

<!-- ||||||||||||||||||||||||||||||||||||||||Website content ends here||||||||||||||||||||||||||||||||||||||||||||||| -->
</div>
<!-- Main Content Wrapper Ends Here-->
<?php include("/var/www/html/includes/footer.php"); ?>

HTML_ERROR
}



(This post was edited by tbone587 on Nov 20, 2011, 3:35 PM)


FishMonger
Veteran / Moderator

Nov 20, 2011, 8:19 PM

Post #2 of 5 (846 views)
Re: [tbone587] Using php includes from within perl here document [In reply to] Can't Post

Why would you expect a here doc to execute php code in that manner?

A here doc is another form of quoting strings. While it is possible to execute arbitrary code within a here doc, it's certianly not the proper approach.

If you want to include php files, then the proper way to do that would be to use the PHP::Include module http://search.cpan.org/~ambs/PHP-Include-0.34/lib/PHP/Include.pm or the PHP::Interpreter module http://search.cpan.org/~aff/PHP-Interpreter-1.0.2/lib/PHP/Interpreter.pm

Howerver, my personal recommendation would be to drop the php files and other direct html code in your script and instead use one of Perl's template modules. You can start out with HTML::Template http://search.cpan.org/~wonko/HTML-Template-2.10/lib/HTML/Template.pm and work up to one of the more advanced template systems such as Template::Toolkit http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Toolkit.pod or Mason http://search.cpan.org/~jswartz/Mason-2.14/lib/Mason.pm or Catalyst http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.90006/lib/Catalyst.pm


tbone587
User

Nov 20, 2011, 9:30 PM

Post #3 of 5 (841 views)
Re: [FishMonger] Using php includes from within perl here document [In reply to] Can't Post

I thought it would render the code since I was printing it with an html header.. I have my site template broken down with php includes, but I cant get this to work. I tried using the PHP::Include module, but it keeps saying I am missing RecDescent.pm which I see is on my computer.. I dont want to have to print all the html code for header and footer within the perl script. Isnt there an easy way to have it use those php includes?


FishMonger
Veteran / Moderator

Nov 21, 2011, 7:37 AM

Post #4 of 5 (826 views)
Re: [tbone587] Using php includes from within perl here document [In reply to] Can't Post

Sounds like Parse::RecDescent wasn't installed properly. Have you tried reinstalling the module?

Another option would be to call php directly and capture the output and insert it into the heredoc.

untested

Code
my $navigation = `php /var/www/html/includes/navigation.php`; 
my $footer = `php /var/www/html/includes/footer.php`;

sub Html_ErrorOutput
{

print "Content-type: text/html\n\n";
print <<HTML_ERROR

$navigation
<div id="content-wrap" >
<!-- |||||||||||||||||||||||||||||||||||||||Website content begins here|||||||||||||||||||||||||||||||||||||||||||||| -->
<div id="contentheader">Change Phone Display</div>
<div id="maincontent">

$HtmlError

<br/>

</div>

<!-- ||||||||||||||||||||||||||||||||||||||||Website content ends here||||||||||||||||||||||||||||||||||||||||||||||| -->
</div>
<!-- Main Content Wrapper Ends Here-->
$footer

HTML_ERROR
}



tbone587
User

Nov 21, 2011, 12:02 PM

Post #5 of 5 (821 views)
Re: [FishMonger] Using php includes from within perl here document [In reply to] Can't Post

Thank you very much fish monger!!! That solution worked, you are the man as always!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives