Have problem parsing php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sniper
Forum Newbie
Posts: 2
Joined: Tue Jan 24, 2006 9:19 am

Have problem parsing php

Post by sniper »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi everyone

I'm new here and need some help. I'm trying to use some php include codes in my html pages.

And this is what I have:

In the .htaccess

Code: Select all

AddType text/html .php .html
AddHandler server-parsed .html
Options All -Indexes
<Files ".ht*">
order allow,deny
</Files>

In my html pages, I have these:

Code: Select all

<?php
define(NUMBER_SHOW, 2);
$text = glob('http://www.domain.com/randomarticle/*.txt');
shuffle($text);
for ($i = 0; $i < NUMBER_SHOW; ++$i) {
    include($text[$i]);
}
?>
NOTE: This is a php code that is suppose to read into a folder and pulls out random files to be displayed.

Code: Select all

<?php include('http://www.domain.com/adsense.php'); ?>
NOTE: This is a php include tag.

I don't think there's any problem with the htaccess because there was no error generated, meaning it was able to read the php lines.

However, nothing gets displayed, be it the random files, or the adsense code.

I've no idea what went wrong. Can someone please advise me?

TQ

- Darren


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

I think the include in the "for" loop needs quotes

Code: Select all

include("$text[$i]");
and I would try double quotes rather than single quotes in the adsense include statement.

(Are you sure the files are there?)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It should be:

Code: Select all

define('NUMBER_SHOW', 2);
(#10850)
sniper
Forum Newbie
Posts: 2
Joined: Tue Jan 24, 2006 9:19 am

Post by sniper »

Hi Feyd

My boo-boo. Sorry for not using the code tags and thanks for pointing it out to me.

Hi Bill and arborint

I changed according to your suggestions and it still didn't work. So what I did was edit the .htaccess file to this:

Code: Select all

AddHandler application/x-httpd-php .php .html
Now, the Adsense include DO WORK! Thanks.

However, for the random code, it generated an error.

This is the code I'm using now:

Code: Select all

<?php
define('NUMBER_SHOW', 2);
$text = glob('http://www.domain.com/randomarticle/*.txt');
shuffle($text);
for ($i = 0; $i < NUMBER_SHOW; ++$i) {
    include("$text[$i]");
}
?>
In my randomarticle folder, I have put in 4 test files: 1.txt 2.txt 3.txt and 4.txt

None of them was pulled out and got this error instead:
Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in /home/domains/domain.com/web/index.html on line 28

Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in /home/domains/domain.com/web/index.html on line 28
Any idea what happened now? My hair is getting less and less due from the scratching of my scalp :roll:

TQ.

- Darren
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

it tried to include a file with the path and name of '' (i.e. no name)

Which of course cannot be possible :)

This means that at some point, $text[$i] has no value. Probably because you can't glob over http :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try changing

++$i

to

$i++
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

It's not finding the files. The pathname must be in error, or the files do not exist in the specified folder.

Jenk had it right. From the php manual for glob():
Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.
Post Reply