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. -
<?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 -
<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>
-
-
23 1924
the line echoing $temp and $arr[i] do not display it shows a icon similar broken page.
neither of them produces valid HTML. and if I read fgets() right, the line break is included and thus neither of your conditions match.
I’m not sure why you want to edit the XML this way.
just testing various ways. so what do i need to do now to get this working as i dont think the values r being put into the arr[i] and re written
maybe there is a better way of doing this …
of wat? deleting from xml? how ... currently it creates a array from the data i want after comparing it with $start $end and $mybody...and then writes this array to the xml....
wat other way?
depending on the circumstances, you can also read the file in a string and do a string replacement.
isnt that what i m doing currently
in the line 31 doesnt it add the string in the $temp to the array?
doesnt $temp hold the line from the xml?
in the line 31 doesnt it add the string in the $temp to the array?
only if the condition is met.
PS. easy appending an element to an array:
ok so when the condition is met it shud add right...but in the script it does show the existing contents of the file but add an additional </gallery> again below the one already existing...y is tht so? and it writes the content too when the condition is not met.
can u plz test the code on localhost u will understand wat i say.
in the line 21 doesnt $temp hold the string line from the xml file?
upon testing the script does what it should do. and may I remind you of what I said in post #2?
how do i get rid of linebreak?
but the linebreak is /> which is part of the script so if i use str replace wont it get rid of that too?
i have put the lines -
$temp =str_replace("\r", "", $temp);
-
$temp =str_replace("\n", "", $temp);
-
below line 21 to remove line break but it still doesn't delete the line that matches the entered value but instead it all in 1 line.
but instead it all in 1 line.
obviously, you remove every line break in the file (which doesn't matter from the XML-point-of-view).
judging from my test you don't need to worry about the line breaks. but it still seems like overkill to do it this way.
but y isnt it overwriting cthe existig file properly
ol one thing when i echo back $start or $ end they r empty they r not echoing back anything y is tht so?
how can i get php to trest < or > as string
for a change, try the functions mentioned in post #10.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pelle |
last post by:
Hello all,
I have to admit, that the idea that occurred to me recently is weird.
It was somehow inspired by the huge response on the "delete operator"
thread, but goes into a somewhat different...
|
by: Cylix |
last post by:
I have a 4row x 1col table, I would like to drop all the content of row
three.
Since Mac IE5.2 does not suppport deleteRow method,
I have also try to set the innerHTML=''; but it does not work.
...
|
by: Laphan |
last post by:
Hi All
I'm using the below to limit the input into a text box to just letters,
numbers, hyphens and full stops, but I also need to allow the backspace,
delete and arrow keys to come through. ...
|
by: bluez |
last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record.
...
|
by: prosad |
last post by:
Hi!
Have been hitting my head on the wall for two weeks now. am a php newbie. have a form that on submitting to a MySQL DB instantly generates a HTML table on the same page. what i need now is way...
|
by: jmarcrum |
last post by:
Hello all!
i have a “monitor-type” program, where my program recognizes my defined "commands”, and executes the given command, or produces an error message that says “unrecognized command”. After...
|
by: Slickuser |
last post by:
From my PHP page:
Grab all data from the database.
Go through a loop to generate the HTML.
Client side:
From the Color drop menu list, if a user change the value. It will
grab that value &...
|
by: ahilar12 |
last post by:
Hi all,
I am new to php,my question is that in this following code i am retrieving many rows from the database which is working good.i want to delete a particular row(s) which is checked(checkbox)...
|
by: shivasusan |
last post by:
Hi!
I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |