Look for some words, and remove them.

Posted on 2011-04-28
Last Modified: 2012-05-11
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"?

Question by:TIgerV
    1 Comment
    LVL 27

    Accepted Solution

    Try this:

        $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 />";     
        $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];
                    $result .= $second[$i].",";           
            $result = substr($result,0,-1);
            $test[$key] = $result;
        echo"<br />after:<br />";     
        echo"<br /><br />And the removed string:<br >";

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now