I'm trying to remove data would text files on the fly from text files using preg_replace: The cat that looks like a tiger is possessed. Code (markup): and I want to use preg_replace() to make it looke like: The cat is possessed. Code (markup): I would like to use the preg_replace() but other ideas would proably be helpful too.
I think preg_replace is OK to use here. Maybe you can try something like : <?php $string = 'The cat that looks like a tiger is possessed.'; $pattern = '/that looks like a tiger /'; $replacement = ''; $new_string = preg_replace($pattern, $replacement, $string); echo $new_string; ?> PHP: or, maybe a str_replace can be useful too... i.e. $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); // will output : You should eat pizza, beer, and ice cream every day PHP: