regex - Remove unknown contents of a text file in PHP -
is there way remove contents (substring) of text file in php.
i know start , end of string remove, not in between content
file (routes.php) want edit
i want maintain text here # [[[@-100] want remove comment line here want remove text here # want remove line [@-100]]] want maintain line so want remove content block starts # [[[@-100] , ends [@-100]]]
im using codeignighter write file so
$route_file ='system/routes.php' $output = file_get_contents($route_file); $output = $output->remove_substring(...); $this->write_file($route_file, $output);
tested:
$mystring='this # [[[@-100] not [@-100]]] string want'; echo remove_substring('# [[[@-100]','[@-100]]]',$mystring); function remove_substring($head,$foot,$string){ $top=reset(explode($head,$string)); $bottom=end(explode($foot,$string)); homecoming $top.$bottom; } output:
this string want
here's version not homecoming errors:
tested:
$mystring='this # [[[@-100] not [@-100]]] string want'; echo remove_substring('# [[[@-100]','[@-100]]]',$mystring); function remove_substring($head,$foot,$string){ $top=explode($head,$string); $top=reset($top); $bottom=explode($foot,$string); $bottom=end($bottom); homecoming $top.$bottom; } php regex codeigniter
No comments:
Post a Comment