wat i m trying to do is delete a line from the xml based on the line generated i.e $mybody dynamically from the values entered by the user.
in the code i provide...it simply adds a line </gallery> belowe the existing line of </gallery> and the line echoing $temp and $arr[i] do not display it shows a icon similar broken page. just run the code n u will understand wat i m saying.
here's the xml file
in the code i provide...it simply adds a line </gallery> belowe the existing line of </gallery> and the line echoing $temp and $arr[i] do not display it shows a icon similar broken page. just run the code n u will understand wat i m saying.
Code:
<?php
$myheading="";
$mylink="";
$mybody="";
if (isset($_POST['submit'])) {
$mylink = $_POST["link"];
$myheading = $_POST["heading"];
$mybody = '<image heading="'.$myheading.'" links="'.$mylink.'"/>';
$start = "<gallery>";
$end = "</gallery>";
$file = "article.xml";
$i=$len=0;
$arr=array();
$handle = fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$temp = fgets($handle);
echo $temp;
if ($temp=="$start"){
$arr[$i]="$start";
$i++;
}
if($temp=="$end"){ $arr[$i]="";
$i++;
}
if ($temp !="$start" && $temp !="$end" && $temp != $mybody){
$arr[$i]="$temp";
$i++;
}
}
$len=$i;
fclose($handle);
}
$handle = fopen($file,"w");
if ($handle) {
$i=0;
while ($i<$len) {
fwrite($handle,$arr[$i]);
echo $arr[$i];
$i++;
}
fwrite($handle,"\n$end");
fclose($handle);
$process="complete";
}
else {
$process="incomplete";
}
}
?>
<table id="structure">
<tr>
<td id="page">
<h2>delete data</h2>
<?php if (!empty($process)) {echo "<p class=\"message\">" . $process . "</p>";} ?>
<form action="delete_p.php" method="post">
<table>
<tr>
<td>heading</td>
<td><input type="text" name="heading" maxlength="23" value="<?php echo htmlentities($myheading); ?>" /></td>
</tr>
<tr>
<td>links</td>
<td><input type="text" name="link" maxlength="40" value="<?php echo htmlentities($mylink); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="delete data" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
here's the xml file
Code:
<gallery> <image heading="google" links="google"/> <image heading="reidff" links="rediff"/> <image heading="g" links="g"/> <image heading="jerk" links="jerk"/> <image heading="jack" links="jack"/> </gallery>
Comment