Thanks a bunch. This got me started, but the results are not always consistant. For example, I set up a test page with a static question to enter ($string). When I execute the page, only portions of $string get inserted.
$string = "If an SLA provides 2 analog ports how many analog ports will an IP SLA provide?";
$charlist = array("`","~","!","@","#","$","%","^","&","*","(",")","_","=","+","\\","|","]","}","[","{","'","\"",";",":","/","?",".",">","<");
$singleChar = array(" a "," b "," c "," d "," e "," f "," g "," h "," i "," j "," k "," l "," m "," n "," o "," p "," q "," r "," s "," t "," u "," v "," w "," x "," y "," z ");
$charlistStripped = str_replace($charlist, " ", $string);
$singleCharStripped = str_replace($singleChar, " ", $charlistStripped);
$singleCharStrippedLower = strtolower($singleCharStripped);
$trimmed = trim($singleCharStrippedLower," ");
$exploded = (explode(' ', $trimmed));
$a = $exploded;
foreach ($a as $v) {
$sqlQuizFrequencyCount = "SELECT frequency FROM quizFrequency WHERE word LIKE '$v'";
$sqlQuizFrequencyCountResult = mysql_query($sqlQuizFrequencyCount) or die(mysql_error());
while ($row = mysql_fetch_array($sqlQuizFrequencyCountResult))
{
$frequencyFound = $row['frequency'];
}
if (is_null($frequencyFound)) {
$sqlQuizFrequencyInsert = "INSERT INTO quizFrequency (word) VALUES ('$v')";
} else {
$frequencyFound ++;
$sqlQuizFrequencyInsert = "UPDATE quizFrequency SET frequency = $frequencyFound WHERE word = '$v'";
}
$sqlQuizFrequencyInsertResult = mysql_query($sqlQuizFrequencyInsert) or die(mysql_error());
}
echo "Done !!";
When I execute this page I get:
uid | word | frequency
1 if 1
2 an 2
3 sla 2
4 provides 1
5 2 1
6 analog 2
7 ports 2
8 how 1
9 many 1
But my string was If an SLA provides 2 analog ports how many analog ports will an IP SLA provide? It's missing the words will, ip and provide. Any ideas? I know my code is less than efficient, so any rewriting you can offer will be appreciated
Thanks