/    Sign up×
Community /Pin to ProfileBookmark

using preg_replace to delete spcific lines from a file

Hi everyone, I don’t post much because I like to search first, well I have searched (google and here), and bothered Omega and have gotten stuck (heck Omega is the reason I’m THIS far…he did a lot of what you will see on the script itself ~thanks Omega!) anyway, basically I’m making a feedback form that has an admin area where the admin can view the comments and delete them when he/she is done.
Right now I have the script that makes the comments and the ability to view them, but I can’t figure out the delete. Thus far the best I have come up with is this:

[code=php]
if (isset ($_POST[‘submit’])) { // Handle form.
if(empty( $_POST[“delete”])) {
echo “Please enter the id of the message you wish to delete.<br />”;
} else {
$data = “feedback.xml”; //the file that it works with
$string = file($data); // turn the file into the string
// I believe this line is my problem: what it is supposed to be is $to_delete uses a regular expression to match:
//<entry>
// <number>[the id of the to-be-deleted post AKA $delete]</number>
// <name>[a word]</name>
// <email>[a word]</email>
// <message>[words]</message>
//</entry>
$to_delete= “/<entry>t<number>$delete</number>nt<w+>w*</w+>nt<w+>w*</w+>nt<w+>w*</w+></entry>/”;
$replacement = “”; // what it will be replaced with (nothing)
preg_replace($to_delete, $replacement, $string);
} //end else
}//end handling the form
//I also don’t know how to then write this to the file, or if, by using preg_replace it IS being written to the file….
[/code]

If you want to see it all you can go [URL=http://literside.net/test/feedback/admin.php]the page[/URL] and see it in context. Note: to see the error you have to try to delete a post, then you will see why I am so stuck.

Thanks ahead of time for all your help ?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @akadis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...