unable to write a file
Posted: Tue Dec 12, 2006 12:56 am
feyd | Please use
CODE FOR TEST.html
what can i do . please help
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am facing a problem in 'FILE WRITING' in PHP . I have just open the file, read its contents, replaces some string. But when i write the file again, it will write the new string at the end of the file. I want to replace the new string with the old string at the same position. What can i doCode: Select all
$filename = "test.html";
$handle = fopen($filename, "a");
$contents = fread($handle, filesize($filename));
$pattern = '!<img src="([^"]+)"!';
$replace = '<img src="x/y/z/$1"';
str_replace($pattern, $replace, $file[1]);
fwrite($handle,"$replace");Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<table width="200" border="1">
<tr>
<td><img src="Water_lilies.jpg" width="100" height="100">cvcxvcxv</td>
<td><img src="Winter.jpg" width="100" height="100"></td>
</tr>
<tr>
<td>This is Row 3 </td>
<td>This is Row 4 </td>
</tr>
</table>
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]