conversion of html content to 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
amitshetye
Forum Newbie
Posts: 12
Joined: Thu Dec 01, 2005 12:00 am

conversion of html content to php

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

file_get_contents()

Code: Select all

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

echo $file;
amitshetye
Forum Newbie
Posts: 12
Joined: Thu Dec 01, 2005 12:00 am

Post 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.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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);
?>
Post Reply