note 86663 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:28:32 +0000 |
| Subject: | note 86663 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154832@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
@samundra dot shr at gmail dot com
You can simplify this a lot by using str_replace to do the work for you
<?php
$filename=$_POST['filename'];
if(!$fpin=@fopen($filename,"r"))
{
print "<b>Error ! File Doesn't Exists</b>";
exit();
}
$text='';
while(!feof($fpin))
{
$text.=fread($fpin,1024);
}
$newtext = str_replace(array("\n", "\r"), '', $text);
$fp=fopen("sample.txt","wb+");
fwrite($fp,$newtext);
fclose($fp);
print "File Changed Successfully.";
?>
Or simply using php5 and not needing to do all the fread/fwrite
<?php
$filename=$_POST['filename'];
if(file_exists($filename)) {
file_put_contents('sample.txt', str_replace(array("\n", "\r"),
'', file_get_contents($filename)));
}
else {
print "<b>Error ! File Doesn't Exists</b>";
}
?>