Page 1 of 1

conversion of html content to php

Posted: Thu Dec 01, 2005 12:15 am
by amitshetye
hi all,

i'm newbie to php

is it possible to convert the web page html content into php and store it into the variables in php.

i have found couple of softwares that converts the html content into php but each time i had to do it
manually. I want to change html content into php dynamically.

so anybody is having any idea?

regards

:)
amit

Posted: Thu Dec 01, 2005 12:23 am
by s.dot
PHP is embeddable (is that a word?) into your HTML page. In reality you could simply change your extension from .html to .php and it will be a PHP page.

Posted: Thu Dec 01, 2005 12:23 am
by n00b Saibot
amitshetye wrote:to convert the web page html content into php and store it into the variables in php.
what do you exactly mean by that phrase :?:
— to store the html page contents into a PHP variable or
— to change portions of HTML page to incorporate PHP code for making it dynamic

Posted: Thu Dec 01, 2005 12:25 am
by John Cartwright
file_get_contents()

Code: Select all

$file = file_get_contents('http://forums.devnetwork.net');

echo $file;

Posted: Thu Dec 01, 2005 3:24 am
by amitshetye
Thanx guys,

for giving me the reply

i had write the following code

$file = file_get_contents('http://forums.devnetwork.net');

echo $file;

by that i can get the whole html page along with the tags

but i want to store it into the php variable

see the following:

<html>
<title>Test</title>
<body>This is test to convert html into php </body>
</html>

so from the above html page i want to store the content between the <title></title> and <body></body> into the variable in php so that i can load it into the flash.

Posted: Thu Dec 01, 2005 3:31 am
by mickd
you could use strip tags on it but then how would you distinguish between what was in what tags.

or

you have to use regular expressions to take out the information you want and store it in a variable.

Posted: Thu Dec 01, 2005 4:00 am
by n00b Saibot
use PHP & Code tags while posting code!

you can do following...

Code: Select all

<?php
$file = file_get_contents('http://forums.devnetwork.net'); 

//capture title
preg_match("#<title>(.*)</title>#i", $file, $match);
$title = $match[1];

//capture body
preg_match("#<body[^>]*>(.*)</body>#i", $file, $match);
$body = $match[1];

echo "Title &rarr; $title<br />Body &rarr; ".htmlentites($body);
?>