would it be appropriate to use PHP's sscanf to read user submitted sentences and try to get data from them? For example:
User inputs:
"James is child of Bill"
and I want to make $child="james"
and $parent="bill"
or: "Mary is the mother of kate"
and I want to make $child="kate"
and $parent="mary"
There could be quite a few other possible sentence formats that I would have to extract data from (no more than 100-ish).
So should I use:
$templates = array("%s is a child of %s","%s is the mother of %s");
$i=0;
$max = count($templates);
while( ($test == -1) && (i < $max) ) {
$test = sscanf($userInput, $templates[i]);
$i++;
}
if(i < $max) {
sscanf($userInput, $templates[i],$child,&parent);//hmm, what if $child,&parent should be the other way around?
} else {
echo "template not found for sentence";
}
? So I'm in a bit of a rut as you can see, can anyone suggest a better way of doing it, or a way to get this solution working?
Really appreciate it!