Here's what I'm doing:
I've created a PHP Sidebar so that I can keep my bookmarks somewhere else besides the top. Plus it's going to serve other purposes as well, but here's my problem. I have the bookmarks storing in a bkm file (file extension I madeup) which is just a standard text file basically. Here's how it stores items:
http://www.apple.com/
Apple
http://www.google.com/
Google
Exactly like that. Now I want to remove one of my bookmarks cause I don't need it or want it anymore so let's remove Google. I want to only pass Google as the argument and have it remove the previous line from being put in the HTML file. How am I gonna do this? Here's the code I have now for what it's worth:
I've created a PHP Sidebar so that I can keep my bookmarks somewhere else besides the top. Plus it's going to serve other purposes as well, but here's my problem. I have the bookmarks storing in a bkm file (file extension I madeup) which is just a standard text file basically. Here's how it stores items:
http://www.apple.com/
Apple
http://www.google.com/
Exactly like that. Now I want to remove one of my bookmarks cause I don't need it or want it anymore so let's remove Google. I want to only pass Google as the argument and have it remove the previous line from being put in the HTML file. How am I gonna do this? Here's the code I have now for what it's worth:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive">
<title>SSP</title>
<style type="text/css" media="screen"><!--
#layer1 { background-image:url('http://192.168.0.2/paper.png'); visibility: visible; position: absolute; top: 10px; left: 10px; width: 168px; height: 182px }
#layer2 { background-color:#FFFFFF; border:2px solid #000000; visibility: visible; position: absolute; top: 200px; left: 10px; width: 168px; height: 151px }
#layer3 { visibility: visible; position: absolute; top: 360px; left: 10px; width: 168px; height: 170px }
--></style>
<script language='javascript'>
function goPage(a)
{
window.open(a, '_main');
}
</script>
<?php
if(($_REQUEST['nameTB']) && ($_REQUEST['linkTB']))
{
$hdl = fopen('bookmarks.bkm', 'a');
if($hdl){
fputs($hdl, $_REQUEST['linkTB']);
fputs($hdl, "\n");
fputs($hdl, $_REQUEST['nameTB']);
fputs($hdl, "\n");
}
fclose($hdl);
}
if($_REQUEST['removeLine2'])
{
$key2 = $_REQUEST['removeLine2'];
echo $key2;
//load file into $fc array
$fc=file("bookmarks.bkm");
//open same file and use "w" to clear file
$f=fopen("bookmarks.bkm","w");
//loop through array using foreach
foreach($fc as $line)
{
if (strstr($line,$key2)) //look for $key in each line
{
echo rtrim($line);
}else{
fputs($f,$line); //place $line back in file
}
}
fclose($f);
}
?>
</head>
<body bgcolor="#9999ff" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
<div id="layer1">
<div align="center">
<font size="+5" color="#8a0124" face="Zapf Chancery, Comic Sans MS, cursive"><b><font size="5"> Favorite Bookmarks<br>
<br>
</font></b></font>
<form>
<select name="selectName" size="1">
<option selected>Choose</option>
<?php
$hdl = fopen('bookmarks.bkm', 'r');
if($hdl){
while(!feof($hdl)){
$ln = fgets($hdl);
if($ln != ''){
echo "<option value=\"$ln\">";
}
$ln = fgets($hdl, 1024);
if($ln != ''){
echo "$ln";
echo "</option>";
}
}
}
else
{
echo "<option>CODE REVISION</option>";
}
fclose($hdl);
?>
</select><br><input type='button' value='Go!' onClick="goPage(selectName.value);"></form>
</div>
</div>
<div id="layer2">
<div align="center"><form method="post" action="sidepanel.php">
URL
<hr width="50px">
<input type="text" width="50px" name="linkTB" size="12"><br>Name
<hr width="50px">
<input type="text" width="50px" name="nameTB" size="12"><br><input type='submit' value='Add Bookmark'></form>
</div>
</div>
<div id="layer3">
<form><center>
<select name="removeLine2" size="0" >
<option selected>Choose</option>
<?php
$hdl = fopen('bookmarks.bkm', 'r');
if($hdl){
while(!feof($hdl)){
$ln1 = fgets($hdl);
if($ln1 != ''){
echo "<option value=\"$ln1\n";
}
$ln2 = fgets($hdl, 1024);
if($ln2 != ''){
echo "$ln2\">$ln2";
echo "</option>";
}
}
}
else
{
echo "<option>CODE REVISION</option>";
}
fclose($hdl);
?>
</select>
<br><input type='submit' value='REMOVE'>
</form></center>
</div>
<table width="185" border="0" cellspacing="0" cellpadding="0" cool gridx="10" gridy="10" height="768" showgridx showgridy usegridx usegridy>
<tr height="767">
<td width="184" height="767"></td>
<td width="1" height="767"><spacer type="block" width="1" height="767"></td>
</tr>
<tr height="1" cntrlrow>
<td width="184" height="1"><spacer type="block" width="184" height="1"></td>
<td width="1" height="1"></td>
</tr>
</table>
<p></p>
</body>
</html>