-2

I have a text file named Notifications.txt. It contains certain groups of contents. Each group begins with a <grouptitle> tag and ends with a </grouptitle> tag {grouptitle changes> For example here is a sample contents

<schedule> New schedule for Mathematics 307 has been emailed to students </schedule>
<convocation> The convocation of 34th batch will be on may 3rd </convocation

Now I want to delete the data in from <schedule> to </schedule> including the tags using a php website.

How can I do this? And I'm a little short on time so would appreciate if you guys can post a sample code as well

Thanks a ton

andrewsi
  • 10,807
  • 132
  • 35
  • 51

1 Answers1

1

You could do so by replacing the tags and it's contents with regular expressions:

$contents = file_get_contents('path/to/file/Notifications.txt');
$contents = preg_replace("!<schedule>.*?</schedule>\r?\n!s", '', $contents);
file_put_contents('path/to/file/Notifications.txt', $contents);
7ochem
  • 2,183
  • 1
  • 34
  • 42