Removing unwanted data between 2 points

Discussion in 'PHP' started by Zaiaku, Dec 1, 2009.

  1. #1
    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.
     
    Zaiaku, Dec 1, 2009 IP
  2. dsignresponder

    dsignresponder Greenhorn

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #2
    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:
    ;)
     
    dsignresponder, Dec 1, 2009 IP