Bigbruin.com
Home :: Reviews & Articles ::
Forum :: Info :: :: Facebook :: Youtube :: RSS Feed
Search  :: Register :: Log in
PHP help - including variables from separate file
Go To Page 1, 2  Next
Post new topic   Reply to topic    Bigbruin.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Tue, 21 Dec 2004 12:28:45    Post Subject: PHP help - including variables from separate file Reply with quote View Single Post

IceNine and others... Need some help, which is probably simple.

Say I have a PHP file that includes several html files to create the content. But, of those several files, I want one variable from one of the html files to be extracted by the PHP file and used as the php pages title.

Do you know what I mean?

like taking variable "$title" from file a and making it understood and usable in file b.

Thanks.
Back to top
View user's profile Send private message Visit poster's website
Little Bruin
Boo Boo

Joined: 07 Apr 2003
Posts: 667
Location: Pic-A-Nic Basket
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Tue, 21 Dec 2004 13:08:45    Post Subject: Reply with quote View Single Post

You mean if you had in "example.html":
Code:
$title = 'monkey';

And that was included in another file? Is that about what you mean?

_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Tue, 21 Dec 2004 14:32:17    Post Subject: Reply with quote View Single Post

yes.

I would like another file to share that $title = "monkey; by some kind of reference from one file to the other.
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Tue, 21 Dec 2004 14:37:29    Post Subject: Reply with quote View Single Post

I guess I'm sort of confused (sorry). Could you give me a real world example? You could email it to me if neccessary.
_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Tue, 21 Dec 2004 14:44:39    Post Subject: Reply with quote View Single Post

I don't have anything to e-mail you really... just trying to figure this out.

But basically say:

example.html has
$title = 'monkey';

I want index.php (for example) to be able to reference example.html so when I <?php echo $title; ?> in index.php, it knows that it is "monkey"!

Grin
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Tue, 21 Dec 2004 15:03:23    Post Subject: Reply with quote View Single Post

Do you include "example.html" before you echo the title? You could do it a couple ways:

preg_match() it, finding a special tag - not $title = 'monkey' but something like <title>monkey</title>

Or you could change example.html into example.php and in one small spot, just to <?$title = 'monkey'; ?> and the variable would be set.

_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Tue, 21 Dec 2004 15:15:52    Post Subject: Reply with quote View Single Post

I was trying include or require, and it would echo the $title properly, but it would also output the whole 'example'html' page too. Did I include wrong?
Back to top
View user's profile Send private message Visit poster's website
Little Bruin
Boo Boo

Joined: 07 Apr 2003
Posts: 667
Location: Pic-A-Nic Basket
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Tue, 21 Dec 2004 15:18:16    Post Subject: Reply with quote View Single Post

When you include something like that, it will output all HTML as well. If you're just trying to extract the title, you'll have to do a file_get_contents instead of an include. But then you'll have to use preg_match.
_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Tue, 21 Dec 2004 15:34:37    Post Subject: Reply with quote View Single Post

OK... have a basic example of the use of preg match?

thanks man!

Smile
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Tue, 21 Dec 2004 15:39:16    Post Subject: Reply with quote View Single Post

Code:
preg_match("/<title>(.*)<\/title>/i", $html_content, $match);


It creates the variable $match, which is an array. The title will be in $match[0]

_________________

A letter to a soldier
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Bigbruin.com Forum Index -> Software All times are GMT - 4 Hours
Go To Page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Contact Us :: On Facebook :: On Youtube :: Newsletter :: RSS Feed :: FAQ :: Links :: Sponsors :: Privacy Policy
Copyright © 2000 - 2023 Bigbruin.com - All rights reserved