Jump to content

Delete lines in file ( Between given 2 strings )


mart94

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.