Advanced Regex problem.

Discussion in 'PHP' started by Justcars.ie, Apr 8, 2010.

  1. #1
    Hey guys,

    Really need some help with preg_replace that is driving me insane.

    I have a foreach loop such as this

    <?php
    foreach ($example as $row){
    
    $id=$row['id'];
    $string=$row['string'];
    }
    
    Code (markup):
    I would like to do the following in each loop
    <?php
    foreach ($example as $row){
    
    $id=$row['id'];
    $string=$row['string'];
    
    
    //$bad_words=array('bad','rotten');
    
    //REPLACE EACH WORD apart from "bad words" INSIDE THE STRING WITH 
    <a href="$row['id']">WORD FROM THE STRING</a>
    
    }
    Code (markup):
    Help really appreciated:)

    Cheers,

    Stuart
     
    Justcars.ie, Apr 8, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, you can use str_ireplace , passing array $bad_words as [mixed $search] argument.
    Regards :)
     
    koko5, Apr 8, 2010 IP