Page 1 of 1

problem in reading file contents

Posted: Sat Jul 08, 2006 2:14 am
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>

Re: problem in reading file contents

Posted: Sat Jul 08, 2006 9:55 am
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.

Posted: Tue Jul 11, 2006 1:52 pm
by itsmani1
thanks

let me try this.