Search code examples
phpfunctionpreg-matchechofile-get-contents

Ignore data within a certain set of characters with PHP


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');
?>

alt text

Would it be possible to ignore the data in between the asterisks, and the asterisks themselves when I echo out the final function?

alt text


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' ) );