mart94 Posted April 10, 2011 Share Posted April 10, 2011 Hi! What i can't figure out, is how to delete between 2 given strings in another file. Explanation: I have a file, it contains following: ### Start of content 0 ### Some Radom Lines with text 1 ### End of content 0 ### ### Start of content 1 ### Some Radom Lines with text 2 ### End of content 1 ### ### Start of content 2 ### Some Radom Lines with text 3 ### End of content 2 ### And so on, now i need code, which can find line i give and delete between. Something like this: If, i give string: ### Start of content 0 ### Then it will delete this line to the ### End of content 0 ### Hope you can help! All the best: Mart L. Link to comment https://forums.phpfreaks.com/topic/233269-delete-lines-in-file-between-given-2-strings/ Share on other sites More sharing options...
Jnerocorp Posted April 10, 2011 Share Posted April 10, 2011 function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $fullstring = "this is my [tag]dog[/tag]"; $parsed = get_string_between($fullstring, "[tag]", "[/tag]"); echo $parsed; // (result = dog) something along the lines of this may help you Link to comment https://forums.phpfreaks.com/topic/233269-delete-lines-in-file-between-given-2-strings/#findComment-1199655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.