note 86663 added to function.strpos
| From: | Anonymous at osu1 dot php dot net | Date: | Tue, 28 Oct 2008 20:20:43 +0000 |
| Subject: | note 86663 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145908@lists.php.net to get a copy of this message | ||
@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>";
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 208.105.179.6
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/86663
Del: integrated -- https://master.php.net/note/delete/86663/integrated
Del: useless -- https://master.php.net/note/delete/86663/useless
Del: bad code -- https://master.php.net/note/delete/86663/bad+code
Del: spam -- https://master.php.net/note/delete/86663/spam
Del: non-english -- https://master.php.net/note/delete/86663/non-english
Del: in docs -- https://master.php.net/note/delete/86663/in+docs
Del: other reasons-- https://master.php.net/note/delete/86663
Reject -- https://master.php.net/note/reject/86663
Search -- https://master.php.net/manage/user-notes.php