Клубове Дир.бг
powered by diri.bg
търси в Клубове diri.bg Разширено търсене

Вход
Име
Парола

Клубове
Dir.bg
Взаимопомощ
Горещи теми
Компютри и Интернет
Контакти
Култура и изкуство
Мнения
Наука
Политика, Свят
Спорт
Техника
Градове
Религия и мистика
Фен клубове
Хоби, Развлечения
Общества
Я, архивите са живи
Клубове Дирене Регистрация Кой е тук Въпроси Списък Купувам / Продавам 13:38 23.04.24 
Клубове/ Компютри и Интернет / PHP Всички теми Следваща тема Пълен преглед*
Информация за клуба
Тема кирилизация
АвторИвo (Нерегистриран) 
Публикувано20.01.07 14:12  



Как да го накарам да работи с български език
SET VARIABLES
//

// name of XML file which contains your quiz data
$xmlFile = "quiz.xml";

// name of header file
$headerFile = "header.inc";

// name of footer file
$footerFile = "footer.inc";


//
// GET QUIZ DATA
//

// get XML data
$data = implode("", file($xmlFile));

// create XML parser
$parser = xml_parser_create();

// set parser options
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

// parse XML data into arrays
xml_parse_into_struct($parser, $data, $values, $tags);

// free parser
xml_parser_free($parser);


//
// STRUCTURE XML DATA INTO ARRAY
//

// set counter variable for to-be-created questions array
$questionNo = 0;

// cycle through parsed XML data to look for text and answer tags
foreach ($values as $key=>$val) {
// save value to "questions" array if this is a TEXT tag
if ($val[tag] == "TEXT") {
$questions[$questionNo]['text'] = $val[value];
}

// save value to "questions" array if this is a CHOICES tag
if ($val[tag] == "CHOICES") {
$questions[$questionNo]['choices'] = $val[value];
}

// save value to "questions" array if this is an ANSWER tag
if ($val[tag] == "ANSWER") {
$questions[$questionNo]['answer'] = $val[value];

// increment question counter variable
$questionNo++;
}
}


//
// IMPORT POST VARIABLES
//

import_request_variables("p", "post_");


//
// INCLUDE HEADER FILE
//

include($headerFile);


//
// PRINT FIRST QUESTION
//

if (!isset($post_answers)) {
echo "<b>" . $questions[0]['text'] . "</b>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";

// split choices into "choices" array
$choices = explode(", ", $questions[0]['choices']);

// print text field if there are no choices
if (count($choices) == 1) {
echo "<input type=\"text\" name=\"answers[0]\" size=10>\n";
}

// print radio fields if there are multiple choices
else {
// print a radio button for each choice
for ($i = 0; $i < count($choices); $i++) {
echo "<input type=\"radio\" name=\"answers[0]\" value=\"" . $choices[$i] . "\"> " . $choices[$i] . "
\n";
}
}

echo "<input type=\"submit\" value=\"Next Question\">\n";
echo "</form>\n";
}


//
// PRINT NEXT QUESTION
//

elseif (count($questions) > count($post_answers)) {
// get number of next question
$nextQuestion = count($post_answers);

// print question
echo "<b>" . $questions[$nextQuestion]['text'] . "</b>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";

// print answers to previous questions as hidden form fields
for ($i = 0; $i < count($post_answers); $i++) {
echo "<input type=\"hidden\" name=\"answers[$i]\" value=\"$post_answers[$i]\">\n";
}

// split choices into "choices" array
$choices = explode(", ", $questions[$nextQuestion]['choices']);

// print text field if there are no choices
if (count($choices) == 1) {
echo "<input type=\"text\" name=\"answers[$nextQuestion]\" size=10>\n";
}

// print radio fields if there are multiple choices
else {
// print a radio button for each choice
for ($i = 0; $i < count($choices); $i++) {
echo "<input type=\"radio\" name=\"answers[$nextQuestion]\" value=\"" . $choices[$i] . "\">" . $choices[$i] . "
\n";
}
}

// print appropriate button label
if (count($questions) == count($post_answers) + 1) {
echo "<input type=\"submit\" value=\"Calculate Score\">\n";
}
else {
echo "<input type=\"submit\" value=\"Next Question\">\n";
}

echo "</form>\n";
}


//
// CALCULATE AND PRINT SCORE
//

else {
// get number of questions
$noQuestions = count($questions);

// get number of correct answers
for ($i = 0; $i < $noQuestions; $i++) {
// increment "noCorrectAnswers" variable if user has correct answer
if ($questions[$i]['answer'] == $post_answers[$i]) {
$noCorrectAnswers++;
}
}

// calculate score
$score = ($noCorrectAnswers / $noQuestions) * 100;

// round score to nearest whole precentage point
$score = round($score);

// print score
echo "<h2>$score%</h2>\n";

if ($noCorrectAnswers == 0) {
echo "<p>You answered no questions correctly. <a href=" . $PHP_SELF . ">Try again.</a></p>";
}

if ($noCorrectAnswers == 1) {
echo "<p>You answered 1 out of $noQuestions questions correctly. <a href=" . $PHP_SELF . ">Try again.</a></p>";
}

if ($noCorrectAnswers > 1 && $noCorrectAnswers < $noQuestions) {
echo "<p>You answered $noCorrectAnswers out of $noQuestions questions correctly. <a href=" . $PHP_SELF . ">Try again.</a></p>";
}

if ($noCorrectAnswers == $noQuestions) {
echo "<p>You answered all questions correctly!</p>";
}
}


//
// INCLUDE FOOTER FILE
//

include($footerFile);

?>



Цялата тема
ТемаАвторПубликувано
* кирилизация Ивo   20.01.07 14:12
. * Re: кирилизация Bълk   20.01.07 14:39
Клуб :  


Clubs.dir.bg е форум за дискусии. Dir.bg не носи отговорност за съдържанието и достоверността на публикуваните в дискусиите материали.

Никаква част от съдържанието на тази страница не може да бъде репродуцирана, записвана или предавана под каквато и да е форма или по какъвто и да е повод без писменото съгласие на Dir.bg
За Забележки, коментари и предложения ползвайте формата за Обратна връзка | Мобилна версия | Потребителско споразумение
© 2006-2024 Dir.bg Всички права запазени.