• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Look for some words, and remove them.

MySql/PHP database.

I have a tricky one.  I receive nearly 700 news releases a day, and almost all if them have a line towards the end that says (close to):
"He is the son of Jon and Linda Doe of 14th street, anytown, MS." or "She is the daughter of LInda Smith, of Oak Park Drive, Roanoke, IN."

I need to take the street location out, to make it:
""He is the son of Jon and Linda Doe of anytown, MS." or "She is the daughter of LInda Smith, of, Roanoke, IN."

I thought about looking for the word " SON ", skip to the second " of " and deleting from there to  and including the ", ".  


To narrow it down, EVERY release that contains the words "Basic Military Training" will have the line, and the others are not quite as important to remove the data from.  90% or more of my posts have "Basic Military Training" in them; and those are the ones I'm concerned with.

If you would like to see some specific examples, I can give you the site's address, but the explanation above pretty much covers it.

Oh- and for further challenge, could I save the removed words in a field named "addy"?

Thanks,
TONY
0
TIgerV
Asked:
TIgerV
1 Solution
 
Lukasz ChmielewskiCommented:
Try this:

<?php
    $test = array("He is the son of Jon and Linda Doe of 14th street, anytown, MS.",
                "She is the daughter of LInda Smith, of Oak Park Drive, Roanoke, IN.");
           
    echo"before:<br />";     
    print_r($test);
    
    $removed = array();
                
    foreach($test as $key => $val){

        $split = explode("of",$val);
        $result = $split[0]."of".$split[1]."of";

        $second = explode(",",$split[2]);
        $len = count($second);
        
        $removed[] = $second[1];

        for($i=1;$i<$len;$i++){
                $result .= $second[$i].",";           
        }
        $result = substr($result,0,-1);
        
        $test[$key] = $result;
    
    }
    
    echo"<br />after:<br />";     
    print_r($test);    
    
    echo"<br /><br />And the removed string:<br >";
    print_r($removed);
?>

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now