$str_array = explode(".", $str);
    unset($str_array[0]);
    //return  trim(implode(".",$str_array));
    return html_entity_decode(trim(implode(".", $str_array)));
}
function process_answer($str)
{
    $str = trim($str);
    $f_str = preg_replace("/\\([A-Da-d]\\)/", "", substr($str, 0, 3)) . substr($str, 3);
    return html_entity_decode(trim($f_str));
}
// Retrieve the DOM from a given URL
//$html = file_get_html('file:///var/www/html/quizmaster/upload/uk.html');
$html = file_get_html('/var/www/html/quizmaster/upload/uphjsc12.html');
//echo $html; exit;
$out = fopen('/var/www/html/quizmaster/upload/new.csv', 'w');
fputcsv($out, array('question', 'option_1', 'option_2', 'option_3', 'option_4', 'correct_answer', 'category', 'explanation', 'multi_answer'));
// Find all "span" tags and print their HREFs
foreach ($html->find('span') as $element) {
    // echo $element. '<br>';
    $keywords = explode("<br />", $element);
    //question,option_1,option_2,option_3,option_4,correct_answer,category,explanation,multi_answer
    $cnt = count($keywords);
    for ($i = 3; $i < $cnt; $i = $i + 6) {
        fputcsv($out, array(process_question($keywords[$i]), process_answer($keywords[$i + 1]), process_answer($keywords[$i + 2]), process_answer($keywords[$i + 3]), process_answer($keywords[$i + 4]), '', '', '', ''));
    }
    pr($keywords);
    echo "---------------------<br>";
}
fclose($out);
exit;
//$prompt = "";
$responseMessage = "";
if ($message != "" && $uiid != "") {
    $ref = "";
    $content = "";
    $cmd = parseCommand($message, $ref, $content);
    $responseMessage = "parseCommand returns [" . $cmd . "] ref=[" . $ref . "] content=[" . $content . "]";
    $con = dbopen();
    if ($cmd == "lg") {
        $responseMessage = process_list_groups($con, $uiid, 0);
    } else {
        if ($cmd == "query") {
            $responseMessage = process_query($con, $uiid, $ref, $content);
        } else {
            if ($cmd == "ans") {
                $responseMessage = process_answer($con, $uiid, $ref, $content);
            } else {
                if ($cmd == "lq") {
                    $responseMessage = process_list_queries($con, $uiid, $ref, $content);
                    // ref for groupId, content for queryId
                } else {
                    if ($cmd == "la") {
                        $responseMessage = process_list_answers($con, $uiid, $ref, $content, 0);
                    } else {
                        if ($cmd == "next") {
                            $responseMessage = process_list_next($con, $uiid);
                        } else {
                            if ($cmd == "fg") {
                                $responseMessage = process_following_group($con, $uiid, $ref);
                            } else {
                                if ($cmd == "fq") {
Example #3
0
function learn(&$user, $filter)
{
    $card = next_card($user, $filter);
    if ($card == NULL) {
        return false;
    }
    $user_card = sql_single_query("select * from user_cards where user_id = {$user['id']} and card_id = {$card['id']}");
    $mylang = $user['language'];
    // pick out the second language from a (for example: /en-ro/) tag (which should be the first tag)
    // note this only works for language cards, this needs work WORK !!!
    $learning = substr($card['tags'], 4, 2);
    $language = get_translated_language($mylang, $learning);
    $prompt = array("en" => "What is the {$language} for ", "nl" => "Wat is het {$language} voor", "de" => "Wie sagt man auf {$language}", "ro" => "Cum se zice in {$language}")[$mylang];
    $goodanswer = array("en" => "the right answer was", "nl" => "het goede antwoord was", "de" => "die richtige antword war", "ro" => "bun resuns e");
    $front = json_decode($card['front'], 1);
    $back = json_decode($card['back'], 1);
    $exposure_start = microtime(true);
    // prompt the user and wait for the answer
    if (abs($user_card['first'] - time(0)) < 5) {
        $fresh = red("*");
    } else {
        $fresh = " ";
    }
    $answer = termline("{$fresh} {$prompt}: " . color_string($front['sp'], "yellow") . " ");
    $exposure_took = intval(1000 * (microtime(true) - $exposure_start));
    if ($answer === NULL) {
        return false;
    }
    if (process_answer($user, $card, $answer, $exposure_took)) {
        echo correct($mylang);
        $user['ngood']++;
    } else {
        $user['nfalse']++;
        echo $goodanswer[$mylang] . ": " . color_string($back['sp'], "yellow") . "\n";
        echo wrong($mylang);
    }
    $ratio = intval(100 * ($user['ngood'] / ($user['ngood'] + $user['nfalse'])));
    $interval = sql_simple_query("select `interval` from user_cards where id={$user_card['id']}");
    echo "! took {$exposure_took} ms, right this session: {$ratio}% total score {$user['score']} next in {$interval} seconds\n";
    echo "\n";
    echo "\n";
    return true;
}
}
// Retrieve the DOM from a given URL
//$html = file_get_html('file:///var/www/html/quizmaster/upload/uk.html');
$html = nl2br2(file_get_contents('/var/www/html/quizmaster/upload/GKindiagktime.html'));
//echo $html;
$htmlArray = explode("<br />", $html);
$out = fopen('/var/www/html/quizmaster/upload/new.csv', 'w');
fputcsv($out, array('question', 'option_1', 'option_2', 'option_3', 'option_4', 'correct_answer', 'category', 'explanation', 'multi_answer'));
// Find all "span" tags and print their HREFs
$cnt = count($htmlArray);
$i = 0;
while ($i < $cnt) {
    $i = $i + 2;
    $data = array();
    $data['question'] = $htmlArray[$i++];
    $data['option_1'] = process_answer($htmlArray[$i++]);
    $data['option_2'] = process_answer($htmlArray[$i++]);
    $data['option_3'] = process_answer($htmlArray[$i++]);
    $data['option_4'] = process_answer($htmlArray[$i++]);
    $i++;
    $data['correct_answer'] = process_answer_option($htmlArray[$i++]);
    $data['category'] = "6";
    $data['explanation'] = "";
    $data['multi_answer'] = "";
    pr($data);
    //question,option_1,option_2,option_3,option_4,correct_answer,category,explanation,multi_answer
    fputcsv($out, array($data['question'], $data['option_1'], $data['option_2'], $data['option_3'], $data['option_4'], $data['correct_answer'], $data['category'], '', ''));
    echo "---------------------<br>";
}
fclose($out);
exit;
        //echo "<b>$uiid $userid</b><br>Phone: $phone<br>City: $city<br>Country: $country<br><hr><br>";
    }
    $i++;
}
$responseMessage = "";
include "bpwelcome.php";
if (strlen($responseMessage) == 0) {
    //echo "\n user_body = " . $user_body . "\n";
    if (startsWith($user_body, "lg:")) {
        $responseMessage = process_group($con);
    } else {
        if (startsWith($user_body, "query:")) {
            $responseMessage = process_query($con, $user_body, $uiid);
        } else {
            if (startsWith($user_body, "ans:")) {
                $responseMessage = process_answer($con, $user_body, $uiid);
            } else {
                if (startsWith($user_body, "lq:")) {
                    //echo "---lq\n";
                    $responseMessage = process_list_queries($con, $user_body, $uiid);
                } else {
                    if (startsWith($user_body, "la:")) {
                        $responseMessage = process_list_answers($con, $user_body, $uiid);
                    } else {
                        if (startsWith($user_body, "next:")) {
                            $responseMessage = process_list_next($con, $user_body, $uiid);
                        } else {
                            if (startsWith($user_body, "fg:")) {
                                $responseMessage = process_following_group($con, $user_body, $uiid);
                            } else {
                                if (startsWith($user_body, "fq:")) {