Ignore data within a certain set of characters with PHP
-
19-09-2019 - |
Question
Not sure what this is called, but is there a way I can pull data from a file, echo it, but ignore data within a certain set of characters?
<?php
echo file_get_contents('test.txt');
?>
Would it be possible to ignore the data in between the asterisks, and the asterisks themselves when I echo out the final function?
Solution
You wouldn't "ignore it" as much as you would "replace it with nothing"
A quick 'n' dirty approach
echo preg_replace( "/\*{3}.*?\*{3}/", "", file_get_contents( 'test.txt' ) );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow