views:

35

answers:

4

Ok I know I can do this via javascript but was wondering if I have say this

<HTML><HEAD><TITLE>Specifics of Bronica SQAi 150/4 PS </TITLE>

<?
include('producttopads.html');

and html processes php can I get the title...

Any ideas. Thanks Richard

A: 

looks like just this will do it ob_get_contents

Richard Housham
...but only if output buffering is enabled **before** the output is sent.
symcbean
Yeah in my case this is exactly what I wanted. Seemed to do the trick anyway!The other ideas will work but only if you are outside of the file. I guess there are lots of ways to do it but this was the best for me
Richard Housham
I am curious how you set this up to make it work for you. From your description of the problem, I can't figure out how this actually does what you are looking for in any (even somewhat) efficient manner. Could you post the solution you used?
Joseph
A: 

Have a look at DOMDocument API. It can parse HTML or XML documents for you.

Example:

$dom = new DOMDocument;
$dom->loadHTML( "<html><title>your_title</title></html>" );
$title = $dom->getElementsByTagName( "title" );
echo $title->item(0)->nodeValue; // your_title
Ondrej Slinták
+1  A: 
// Create DOM from URL or file
$html = file_get_html('http://www.example.com/');

$title = $html->find('title', 0)->innertext;

http://simplehtmldom.sourceforge.net/manual.htm

karim79
+1  A: 

The cleanest way to do it is this:

$pageTitle = "Specifics of Bronica SQAi 150/4 PS";
<HTML><HEAD><TITLE><?php echo $pageTitle; ?> </TITLE>

<?
include('producttopads.html');

Then you can access the title using the variable $pageTitle.

The other ways of doing it will require you to wait until after the page is loaded to access the title which isn't going to work for your purposes as I can tell.

Joseph