Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][XML] Aktualizacja danych w pliku XML , problem
Forum PHP.pl > Forum > XML, AJAX
kumar
Witam.
Mam problem z kodem zamieszczonym poniżej. Prosiłbym o pomoc w znalezieniu powodu występowania błędu.
Z góry dzięki za pomoc.

Kod Generuje następujący błąd :

  1. Parse error: parse error, expecting `','' or `')'' in C:\xampp\htdocs\test\NewsUp.php on line 43


  1. <?php
  2. include_once 'common.inc.php';
  3. $doc = new DOMDocument();
  4. $root = $doc->documentElement;
  5. $maxId = 0;
  6. $deleteFailures = array();
  7. foreach ($root->getElementsByTagName('author') as $xAuthor) {
  8. $id = $xAuthor->getAttribute('id');
  9. if ($maxId < (int)$id) $maxId = (int)$id;
  10. if (isset($_POST['author']) and
  11. isset($_POST['author'][$id])) {
  12. $author = $_POST['author'][$id];
  13. if (isset($author['delete']) and $author['delete'] == 'true')
  14. {
  15. $okToDelete = TRUE;
  16. $handle = opendir($fileDir);
  17. while (($file = readdir($handle)) !== FALSE) {
  18. if (is_dir($fileDir . $file)) continue;
  19. if (!eregi("^(article|news).*\.xml$", $file)) continue;
  20. $contentItem = simplexml_load_file($fileDir . $file);
  21. if ((string)$contentitem->authorid == (string)$id) {
  22. $okToDelete = FALSE;
  23. break;
  24. }
  25. }
  26. if ($okToDelete) $root->removeChild($xAuthor);
  27. else $deleteFailures[] = $id;
  28. } else {
  29. $name = $xAuthor->getElementsByTagName('name');
  30. $name = $name->item(0);
  31. $name->nodeValue = $author['name'];
  32. $byline = $xAuthor->getElementsByTagName('byline');
  33. $byline = $byline->item(0);
  34. $byline->nodeValue = $author['byline'];
  35. $email = $xAuthor->getElementsByTagName('email');
  36. $email = $email->item(0);
  37. $email->nodeValue = $author['email'];
  38. }
  39. }
  40. }
  41. if (isset($_POST['newauthor'])) {
  42. foreach ($_POST['newauthor'] as $author) {
  43. if (isset($author['name'] and trim($author['name']) != '')) {
  44. $xAuthor = $root->appendChild($doc->createElement('author'));
  45. $xAuthor->setAttribute('id', ++$maxId);
  46. $xAuthor->appendChild($doc->createElement('name',
  47. $author['name']));
  48. $xAuthor->appendChild($doc->createElement('byline',
  49. $author['byline']));
  50. $xAuthor->appendChild($doc->createElement('email',
  51. $author['email']));
  52. }
  53. }
  54. }
  55. unlink($fileDir . 'news.xml');
  56. $doc->save($fileDir . 'news.xml');
  57. if (count($deleteFailures) > 0) {
  58. $qs = '?';
  59. foreach ($deleteFailures as $id) {
  60. $qs .= "id[]=$id&";
  61. }
  62. ?>
zenon13
Nie zagłębiałem się jak dokładnie działa ten skrypt ale
akurat w tej linii jest złe użycie funkcji trim http://php.net/manual/en/function.trim.php
brakuje przecinka a to co ma być pomijane ma być w "".
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.