if my input string is "Hello! How are you? I'm fine thank you.", the results will be:
- Array [0] -> Hello! Array [1] -> How are you? I'm fine thank you
- Array [0] -> Hello
- Array [0] -> How Array [1] -> are Array [2] -> you Array [3] -> I Array [4] -> m Array [5] -> fine Array [6] -> thank Array [7] -> you
Code: Select all
<?php
$con = mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("phrasal_lexicon_database", $con);
if ($_POST['submit'])
{
$wordname_form = $_POST['wordname'];
$delimiter="/[.!:;]/";
echo "Input string is <b>$wordname_form</b>. <br/>";
$token=preg_split($delimiter, "$wordname_form", -1, PREG_SPLIT_NO_EMPTY);
echo "<br/> The splitted words are: <br />";
print_r($token);
$counter =count($token);
echo "<br/>The input string is divided into <b> $counter</b>.<br/>";
if (is_array($token))
{
foreach ($token as $o)
{
$delimiter2="/[ ,.\/<>?;\\':\"\[\]\{\}\t\n\r~`!@#$%^&*()-=\\\_+|]/";
$token2=preg_split($delimiter2, $o, -1, PREG_SPLIT_NO_EMPTY);
echo "<br/> The tokenized words from <b> $o </b> are: <br />";
print_r($token2);
for($i = 0; $i < count($token); $i++)
{
foreach($token2 as $key=>$value)
{
$extract=mysql_query("select * from word_categories where id= '. $token2'");
$numrows=mysql_num_rows($extract);
while ($row=mysql_fetch_assoc($extract));
{
$wordnames=$row['word_name'];
$wordcategory=$row['word_category'];
echo "$wordcategory";
}
}
}
}
}
else
{
echo"Failed";
}
}
mysql_close($con);
?>