Hi, I'm not quite sure how else to call this but here is the situation:

I currently use a template file made up of html and a PHP include expression to generate the content. So far, no problem.

Now I would like to add another function that will detect a specific string of text in the content and replace it with another text. In other words, I would like for my script to detect a certain word in included content and replace it with another word (in my case a URL.)

So is there some kind of search and replace function I could use for this? If this isn't clear, feel free to email me directly and I'll supply more info.

Thank you!

    Hope this helps!!

    I knocked this function up which would search through a string and replace words found in the string which exist in a MySQL table.

    <?php

    function ConvertToGlossaryText($ConvertThis) {

    // Get all the glossary terms from the glossary table an store them
    // in an array

    $GlossaryTerms = array();
    
    $SQLQuery = "SELECT glossary_term_id, term FROM glossary_term_tbl ORDER BY glossary_term_id ASC;";
    $Result = mysql_query($SQLQuery);
    
    while ($GlossaryTerms[] = mysql_fetch_array($Result)) {
    
    }
    mysql_free_result($Result);

    // Replace any word found in the article which exists in the glossary
    // array with a reference to the glossary php page

    for ($intWords=0; $intWords < count($GlossaryTerms) -1; $intWords++){
        $GlossaryID = $GlossaryTerms[$intWords] [0];
        $FindThis = $GlossaryTerms[$intWords] [1];
    
        $ReplaceWith = "<A HREF=\"glossary.php?id=$GlossaryID\">$FindThis</A>";
        $ConvertThis = eregi_replace ($FindThis, $ReplaceWith, $ConvertThis);
    }
    
    return $ConvertThis;

    }

    Good Luck
    BB

      Write a Reply...