problem in reading file contents

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

problem in reading file contents

Post by itsmani1 »

I want to read contents of an html file between body tags.
for example : here are contents of html file. and i want to fetch contents between <body bgcolor="#CCCCCC"> and </body> tags. then after doing the modification to this i want to replace between content between body tags using files, i need help in updating file, means when i am updating my file how i can search body tagas and then replace contets between them?

In simple words i want to put my content between <body ....> and </body> tags.

please guide me.

thanks much.


sample html file code.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#CCCCCC">
<p>haya....</p>
<p>this is the required content </p>
</body>
</html>
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: problem in reading file contents

Post by aerodromoi »

itsmani1 wrote:I want to read contents of an html file between body tags.
for example : here are contents of html file. and i want to fetch contents between <body bgcolor="#CCCCCC"> and </body> tags. then after doing the modification to this i want to replace between content between body tags using files, i need help in updating file, means when i am updating my file how i can search body tagas and then replace contets between them?

In simple words i want to put my content between <body ....> and </body> tags.

please guide me.

thanks much.


sample html file code.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#CCCCCC">
<p>haya....</p>
<p>this is the required content </p>
</body>
</html>
If you're using a php script in the first place,

Code: Select all

<body>
<?php echo $content; ?>
</body>
should do the trick (assuming, $content has been declared / initialised).

Or do you mean modifying a html page by reading its content via a php-script and then replacing the file itself?
For this approach I'd recommend preg_match_all.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

thanks

let me try this.
Post Reply