note 86003 added to function.strpos
| From: | samundra dot shr at gmail dot com | Date: | Sun, 28 Sep 2008 06:40:55 +0000 |
| Subject: | note 86003 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144857@lists.php.net to get a copy of this message | ||
This is the code,I wrote today, I wanted to strip all the newlines, and format the output in a
single line so as to lower the filesize of my php source files.
<?php
/****************************************
@ Code By : Samundra Shrestha
@ Dated : September 28,2008
P.S. Remember to remove all single line comments from the source file
otherwise the file may get corrupted.
******************************************/
if(!isset($_POST['change']) || !isset($_POST['filename']))
{
print "<b>".strtoupper("Paste the fullpath of the
file")."</b>";
print "<form name='FrmChange' method='post'
action='".$_SERVER['PHP_SELF']."'>";
print "<input type='textbox' name='filename' size='50px'
maxlength='255'>";
print "<input type='submit' name='change'
value='Start'>";
print "</form>";
}
else
{
$filename=$_POST['filename'];
if(!$fpin=@fopen($filename,"r"))
{
print "<b>Error ! File Doesn't Exists</b>";
exit();
}
$text="";
$i=0;
/*Put the contents of file into the string*/
while(!feof($fpin))
{
$text.=fread($fpin,1024);
}
$count=strlen($text);
$pos=strpos($text,"\n"); //Gives the First occurence of newline
while($i<$count)
{
if($i<$pos-1)
{
$newtext.=$text{$i}; //C Style of String Indexing
}
else
{
$pos=strpos($text,"\n",$i+1);
}
$i++;
}
$newtext.="?>"; //necessary as somehow it is removed from the original source file.
$fp=fopen("sample.txt","wb+");
fwrite($fp,$newtext);
fclose($fp);
print "File Changed Successfully.";
}
?>
The resultant code is all in one new line saved in file sample.txt
I hope, this comes handy to someone.
Cheers,
Samundra Shrestha
http://www.samundra.com.np
----
Server IP: 69.147.83.197
Probable Submitter: 202.70.82.67
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/86003
Del: integrated -- https://master.php.net/note/delete/86003/integrated
Del: useless -- https://master.php.net/note/delete/86003/useless
Del: bad code -- https://master.php.net/note/delete/86003/bad+code
Del: spam -- https://master.php.net/note/delete/86003/spam
Del: non-english -- https://master.php.net/note/delete/86003/non-english
Del: in docs -- https://master.php.net/note/delete/86003/in+docs
Del: other reasons-- https://master.php.net/note/delete/86003
Reject -- https://master.php.net/note/reject/86003
Search -- https://master.php.net/manage/user-notes.php