include a php file inside a perl file??

They have: 164 posts

Joined: Nov 2001

i have this few lines written in perl:

use strict;
use AdBass;
my $bass=AdBass->new();
$bass->{db}->connect($bass,"adbasic");
$bass->{cron}->hourly_update($bass);
$bass->{db}->clean_up($bass);
exit(0);
'

i need to include my php written code after

$bass->{cron}->hourly_update($bass);
'

can i do in this way?

$bass->{cron}->hourly_update($bass);
<?
include "abc.php";
?>
'

if not? how am i suppose to include my php page in this
page?? pls help.. thanks.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

can i do in this way?
No, you can't embed PHP in a PERL file. But , I'm not sure how to do it... I've never done it.

They have: 601 posts

Joined: Nov 2001

What are you trying to do? Print a PHP page to the browser from within a Perl script? Hm, you really ought to stick to one programming language, you know Smiling

To include HTML, PHP, XML or whatever else you want, just slurp it all into a variable (see below). In my example I've also added a print statement to print it to the brwoser, but you can choose to do whatever you want with it after this stage.

my $php_code = <<__PHP__;

  .. put your PHP code in here ..

__PHP__;

print $php_code;
'
Hope this helps.

- wil

They have: 164 posts

Joined: Nov 2001

actually i want to include the php file in the perl script.

include "abc.php";

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You can't because there is no way to get the server to parse two languages in the same file. The extension of the file tells the server how to understand it. You cannot include a php file in any file other than a php file. You can only, like with perl/cgi, link to a php script that would run when clicked, or as the source of an image.

Unless you are just quoting the source (don't need to parse anything) you cannot do it.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Well, you can execute it... sort of (run it as a shell command). I'm not sure that it will have access to the environmental variables though.

They have: 164 posts

Joined: Nov 2001

i do know that when there's something not right in the script, the whole page won't load, but it won't tell any errors. that's wat i have when i used:

use LWP::Simple;
&getprint('http://www.abc.com/test/adcycle/cookie.php');
'

i did try to use this:

my $php_output = `lynx -source <a href="http://www.abc.com/test/adcycle/cookie.php" class="bb-url">http://www.abc.com/test/adcycle/cookie.php</a>`;
'
also can't load the page.

and i used this:

my $php_output = get("http://www.abc.com/test/adcycle/cookie.php") ;
'
no errors found but in my cookie.php i print a word"hello" but when i load my page, that word is not found. so i assume it didn't include my php page either...

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

If you need to parse the contents of cookie.php, you can't do that while in the middle of parsing a perl page.

The problem isn't that it's not including (not entirely), it's that it can't do anything with it. Perl doesn't understand PHP.

They have: 164 posts

Joined: Nov 2001

oh...i get all these code from another forum. they told me i can include my php page through this way. hmm..so wat should i do now...~sigh~

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Those are what I would have recommended.
It didn't even work on a simple "Hello World" script?

They have: 601 posts

Joined: Nov 2001

joyce

That code is a bit sketchy. I would first load the page into memory by doing:

use LWP::Simple;
$content = get("http://www.abc.com/test/adcycle/cookie.php")

print $content;
'

- wil

They have: 5,633 posts

Joined: Jan 1970

Hi, if you can wait for apache 2 Smiling... with filters you `should` be able to achieve exaclty what you want to do, i.e. parse PHP from within PERL & vv , I know you can for instance use SSI in PHP with apache2 but the inputfilter & output filter docs are still a little sketchy Wink

can you go the other way around though ? i.e. write a PHP file and use virtual() to run the PERL script ??

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.