www.webdeveloper.com
Results 1 to 6 of 6

Thread: How can I do a more detailed find and replace ?

Threaded View

  1. #1
    Join Date
    May 2006
    Posts
    245

    How can I do a more detailed find and replace ?

    Hi,

    I am have been using a basic str_replace()
    when swapping out data, but now it has good a bit more complicated.

    My data is in a mysql table and looks like:

    column: name
    Dave
    John
    Dave Brown
    Steve
    Dave H. Brown
    John Graves
    Dave Griffins Brown


    column: address
    Dave:56, Google Ave
    John:77 Jognst Road
    The Beach hut owned by Dave Brown
    Dave H. Brown:55 Frisbie Park Avenue
    Steve:2 Giant Pea Garden
    John Graves:5627 Ant Hill Rise
    Dave Griffins Brown:25 Franks Drive

    My code reads the table and creates arrays:

    PHP Code:
    while ($row mysql_fetch_assoc($result)) {    
      
    extract($row);
      
    $names[] = $name.' ';    
      
    $addresses[] = $address.' ';    
      }
    $new_data str_ireplace($names,$addresses,$input_data); 
    The $input_data looks like:
    "The fireman Dave did something. Then John Graves did something else
    later on Dave Brown came over with Steve The following day police officer Dave Griffins Brown
    was found dead by John";

    ( But of course much longer)

    Clearly if I do the basic str_ireplace() things are going to get mixed up because there
    are 3 names starting with "Dave"

    I guess I may have to abandon the str_ireplace() and perhaps sort the arrays and
    then step through doing a comparison.
    ( or is there a clever way to use str_ireplace() to do this )

    I am not at all sure what is the best way to do this, so would really appreciate your help.

    open to suggestions

    Thanks.
    Last edited by jeddik; 11-16-2013 at 05:46 AM.
    Developers Choice Revealed:
    www.devchoice.info
    Which host has won, and why ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles