title: update SQL contents with hyperlink of other SQL entries by using str_replace in PHP
body: <p>I am working on a dictionary type SQL table. Once I have it completed I have PHP script prepared to update the text with a html hyperlink tag. The script works fine now. However, some of the dictionary entries are phrases and include several words and so the content wont have the proper link associated with them. For example, if I ran the script I currently have it would explode the entire definition and link heart and attack separately. While I wish to have the phrase "heart attack" linked.</p>
  
  <p>WORD: myocardial infarction<BR>
  DEFINITION: Heart attack<BR><BR>
  Any suggestions on how to do this?<BR>
  This is my current script that works.</p>
  
  <pre><code>$def = $original['def'];
  $explode_string = explode(" ",$def);
  $explode_count = count($explode_string);
  $compare_count = 0;
  if($explode_count&gt;0)
  {
      while($compare_count&lt;=$explode_count)
      {
          $sql="SELECT word
               FROM dictionary
               WHERE word='{$explode_string[$compare_count]}'";
  
          $result=mysql_query($sql);
          if(! $result )
          {
            die('Could not get data: ' . mysql_error());
          }
          $row = mysql_fetch_array($result);
          if($row)
          {
              if($explode_string[$compare_count]!="{$original['word']}")
              {
              $replace="&lt;a href=\'http://www.medicresource.com/medicaldictionary/search.php?word=".$explode_string[$compare_count]."\'&gt;{$explode_string[$compare_count]}&lt;/a&gt;";
              $def = str_replace($explode_string[$compare_count], $replace, $def);
              }
  
          }
          ++$compare_count;
      }
  }
  $update_sql = "UPDATE dictionary SET def='$def' WHERE id='{$original['id']}'";
  </code></pre>