Geronantimo
Technical User
I am using a small script for saving code snippets.
The script saves each snippet in a text file. It is adding escape characters to some of the code:
snippet:
and this is how it is saved in the text file:
How can I prevent this from happening?
here is the full script:
The script saves each snippet in a text file. It is adding escape characters to some of the code:
snippet:
Code:
if(strstr($HTTP_ACCEPT_LANGUAGE,"en")) {
and this is how it is saved in the text file:
Code:
if(strstr($HTTP_ACCEPT_LANGUAGE,\"en\")) {
How can I prevent this from happening?
here is the full script:
Code:
<html>
<title><? $title ?></title>
<?
$apass = "password2"; //admin password
$title = "cooolstar snippet code system"; //page title
$navigation = "coolstar"; //name in url links
$instruction = "copy the Text from text box"; //some instructions
$path = './snippets'; //snippets directory
$snippetsystem = "2"; //0 for only veiws, 1 for view and add snippets, 2 for all actions
$action = "0"; //0 for null, 1 for actions comlumn display
$slen = "20"; //snippet name length characters allowed
$self = $_SERVER['PHP_SELF'];
error_reporting(1);
?>
<?
echo "<h2> $title </h2>";
echo "<hr>";
if ($_GET[$navigation]=="") {
echo "Available snippets";
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "<b><table border='0' width='80%' bgcolor='steelblue'><tr><td width='15%'><p align='center'><b>Added</b></td><td width='30%'><p align='center'><b>Snippet name </b></td><td width='25%'><p align='center'><b>Author name</b></td>"; if ($action == 1) { echo "<td width='30%'><p align='center'><b>actions</b></td>"; } echo "</tr></table>";
while ($file = readdir($dir_handle)) {
if(!is_dir($file)) {
$fullpath = "$path/$file";
$open = fopen($fullpath, "r");
$lines = file($fullpath);
$author = "<b>" .htmlentities($lines['0']) ;
$date = date ("d/m/Y", filemtime($fullpath));
fclose($open);
$file = str_replace(".txt", "", $file);
$filelink = base64_encode($file);
echo "<table border='2' width='80%' bgcolor='lightblue'><tr><td width='15%'><p align='center'>$date</td><td width='30%'><p align='center'><a href='$self?$navigation=view&id=$filelink' hidden='$path/$file'>$file</a></td><td width='25%'><p align='center'>$author</td>"; if ($action == 1) { echo "<td width='30%'><p align='right'><a href=$self?$navigation=del&id=$filelink>delete</a></td>";} echo "</tr></table>";
}
}
closedir($dir_handle);
}
if (($_GET[$navigation]=="add")) {
if ($snippetsystem != "0") {
$aname=$_POST['author'];
$fname=$_POST['snippetname'];
$cname=$_POST['addcode'];
if (($aname=='')||($fname=='')||($cname=='')) {
echo "<form method='post' action='$self?$navigation=add'>
<center><b>Author name:</b>     <input type='text' name='author'><br>
<b>Snippet name:</b>    <input type='text' name='snippetname'><br><br>
<b>snippet:</b><br>
<textarea rows=10 name=addcode cols=50 style=font-family: Arial; font-size: 10pt>
</textarea><br><br>
<input type='submit' value='submit snippet' >
</form></center>";
}
else {
if ((strlen($fname) > $slen) || (strlen($aname) > $slen)) {
echo "Snippets name or author name cannot have more then $slen characters.";
exit();
}
$snippet = $path.'/'.$fname.'.txt';
if (!file_exists($snippet)) {
$handle = fopen($snippet, "w");
$success = fwrite($handle, "$aname\n$cname");
if ($success) {
$file = str_replace(".txt", "", $fname);
$dfilelink = base64_encode($file);
echo "<center>Thank you <br>" .$aname ;
echo "<br><B><a href='$self?$navigation=view&id=$dfilelink' hidden='$path/$file'>". $fname ."</a></B>  has been submitted. <br></center>" ;
}
else echo $fname. "cannot be added as a snippets.";
}
else echo "Sorry <b>$fname</b> already on our server"; exit();
}
}
else echo "Sorry snippets add system is temporarily off";
}
if (($_GET[$navigation]=="del")&&($_GET['id']!=="")) {
if ($snippetsystem == "2") {
$dfile = $_GET['id'];
$dfilelink = base64_decode($dfile);
$pass2=$_POST['adminpass'];
if ($pass2=='') {
echo "You are going to delete <b>$dfilelink</b>
<form method='post' action='$self?$navigation=del&id=$dfile'>
<center><b>Password:</b>     <input type='text' name='adminpass'><br>
<input type=submit value='signin' name='adminpass'></center>
</form>";
}
elseif ($pass2 == $apass) {
$fullpath = $path."/".$dfilelink.".txt";
if (file_exists($fullpath)) { unlink($fullpath); echo "<b> $dfilelink </b>has been successfully deleted"; }
else echo "Sorry <b>$dfile</b> snippet doesnot exists ";
}
else echo "Password given is wrong";
}
else echo "Sorry snippet delete system is temporarily off";
}
if (($_GET[$navigation]=="view")&&($_GET['id']!=="")) {
$dfile = $_GET['id'];
$dfilelink = base64_decode($dfile);
$fullpath = $path."/".$dfilelink.".txt";
if (file_exists($fullpath)) {
$author = fopen($fullpath, "r");
$lines=file($fullpath);
echo "snippet name:  <b><a href=$self?$navigation=view&id=$dfile>$dfilelink</a></b> $nbsp   author's name:   <b>" .htmlentities($lines['0']) ."</b><br><br>";
echo "<center><table border=0 cellpadding=0 cellspacing=7 width=80% ><tr>";
foreach ($lines as $line_num => $line) {
if ($line_num != 0) {
$snip = htmlentities($line);
echo "<tr><td bgcolor=silver><font color=red size=2><u>$line_num.</u></font>     "; highlight_string($snip); echo "</td></tr>";
}
}
echo "</table></center><br><br>";
echo "<p><font face=Fixedsys>$instruction</font></p>";
echo "<center>";
echo '<p><textarea rows=8 name=seecode cols=35 style=font-family: Arial; font-size: 10pt> ';
foreach ($lines as $line_num => $line) {
if ($line_num != 0) {
$snip = htmlentities($line);
echo $snip;
}
}
echo ' </textarea></p></center>';
}
else echo "sorry <b> $dfile </b> snippet is not avalible";
}
echo "<hr>";
echo "<br><b><center><a href=$self?$navigation> View snippets </a>   <a href=$self?$navigation=add> Add a snippet</a></center></b><br><br><br>";
//donot modify it, its against rules to GNU lisence. its cooolstar Private porperty
echo "<table width='101%' bgcolor='dimblue'><tr><td><p align='center'><a href='Mailto:emailaddress'>world cooolstar Pakistan</a></td><tr><table>";
?>
</html>