Professional Web Applications Themes

New to PHP, what is the error in this file? - PHP Development

I'm fairly new to PHP. Because I've done some programming years ago I was hoping I could sort of jump into it without going to the absolute basics but I'm thinking that's not the case. What I want is to have a PHP page read data values off of a xml doent and put them into html. I'm using PHP-dev. The problem is when I do a syntax check it doesn't take me to the line where the problem is. So I uploaded the files and IE is telling me "P error: p error, unexpected $ in /usr/home/web/users/a0018893/html/uploads/review.php on line ...

  1. #1

    Default New to PHP, what is the error in this file?

    I'm fairly new to PHP. Because I've done some programming years ago I
    was hoping I could sort of jump into it without going to the absolute
    basics but I'm thinking that's not the case.

    What I want is to have a PHP page read data values off of a xml
    doent and put them into html.

    I'm using PHP-dev. The problem is when I do a syntax check it doesn't
    take me to the line where the problem is.

    So I uploaded the files and IE is telling me "P error: p
    error, unexpected $ in
    /usr/home/web/users/a0018893/html/uploads/review.php on line 125
    "
    which is the ?> at the end. That doesn't make no sense because there
    is no $ in that line.

    What I did was take a tutorial file and try to tailor fit it to what I
    want and if I can get it to work then I want to code my own PHP file
    to write the XML so I don't have to hand type text into the xml file,
    upload it, etc, etc. I read up on syntax, etc, etc and I thought I had
    the gist of it and if I could see it in read mode then I could take
    what I learned about write mode and work with my combined knowledge to
    made the "write" page and like I said it's not going well.

    The XML file(review.xml) looks like this:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <review>
    <id>1</id>
    <title>Zelda</title>
    <body>sweet</body>
    <score>5 Stars</score>
    </review>

    The PHP file (review.php) looks like this:

    <?php
    // the xml file to p
    $xmlSource="review.xml";


    //defined variables

    $id="";
    $title="";
    $body="";
    $score="";

    $currentElement=""; //holds the name of the current element

    $shows=array(); //array to hold all the data

    function endElement($pr,$name){
    $elements=array('id','title','body','score');


    /*After parsing a movie we reset the rest of the globals.*/

    if(strcmp($name,"review")==0){

    $GLOBALS['id']="";

    $GLOBALS['title']="";

    $GLOBALS['body']="";

    $GLOBALS['score']="";

    }

    }//end endElement()


    /* The character data Handler
    * Depending on what the currentElement is,
    * the handler assigns the value to the appropriate variable
    */

    function characterData($pr, $data) {
    $elements = array (
    'id','title', 'body', 'score');

    foreach ($elements as $element) {
    if ($GLOBALS["currentElement"] == $element) {
    $GLOBALS[$element] .= $data;
    }
    }
    }

    /* This is where the actual parsing is going on.
    * pFile() ps the xml doent and return an array
    * with the data we asked for.
    */

    function pFile(){
    global $xmlSource,$shows;

    /*Creating the xml pr*/
    $xml_pr=xml_pr_create();

    /*Register the handlers*/

    xml_set_element_handler($xml_pr,"startElement" ,"endElement");
    xml_set_character_data_handler($xml_pr,"charac terData");

    /*Disables case-folding. Needed for this example*/

    xml_pr_set_option($xml_pr,XML_OPTION_CASE_ FOLDING,false);

    /*Open the xml file and feed it to the pr in 4k blocks*/
    if(!($fp=fopen($xmlSource,"r"))){
    die("Cannot open $xmlSource ");
    }
    while(($data=fread($fp,4096))){

    if(!xml_p($xml_pr,$data,feof($fp))){
    die(sprintf("XML error at line %d column %d ",
    xml_get_current_line_number($xml_pr),
    xml_get_current_column_number($xml_pr)));
    }
    }

    /*Finish ! we free the pr and returns the array*/
    xml_pr_free($xml_pr);

    return $shows;

    }//end pFile()



    /************************************************** *************************************************
    Calling the pFile() and getting the result out in
    a simple html-table
    ************************************************** *************************************************/

    $result=pFile();


    print '<table border="1">';
    foreach($result as $arr){

    /*check on movieId to see if we reached a new movie.
    * If so we print out the movieName
    */
    if(strcmp($id,$arr["id"])!=0){
    print '
    <tr>
    <td colspan="3"><b>'.$arr["title"].'</b></td>
    </tr>
    <tr>
    <td colspan="3">'.$arr["body"].'</td>
    </tr>
    <tr>
    <td colspan="3">'.$arr["score"].'</td>
    </tr>';

    $id=$arr["id"];


    }

    print '</table>';
    ?>


    I would definitely appreciate any help I receive.
    Frank Guest

  2. #2

    Default Re: New to PHP, what is the error in this file?

    Frank Stallone <com> wrote in
    news:com (in part):
     

    Usually you get that error when you're missing a ending brace "}"

    [BIG Snip}

     

    Notice, you have an opening brace after the foreach() and if()
    statements, but you only have one closing brace. You can safely remove
    the opening brace after the if() statement, since you don't need them if
    only one statement is being excuted as a result of the if().

    Ken
    Ken Guest

  3. #3

    Default Re: New to PHP, what is the error in this file?


    Thank you.

    Clearly I need to get back into to the habit of looking over code and
    being able to spot things like that. Unfortuantely I'm probably
    her away from that point than I'd like. ;)


    On Fri, 19 Aug 2005 20:24:56 GMT, Ken Robinson
    <com> wrote:
     
    >
    >Usually you get that error when you're missing a ending brace "}"
    >
    >[BIG Snip}
    >

    >
    >Notice, you have an opening brace after the foreach() and if()
    >statements, but you only have one closing brace. You can safely remove
    >the opening brace after the if() statement, since you don't need them if
    >only one statement is being excuted as a result of the if().
    >
    >Ken[/ref]

    Frank Guest

Similar Threads

  1. Error "Insufficient disk space or other error writing PDF file
    By samszeto@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 2
    Last Post: July 2nd, 03:33 PM
  2. Replies: 1
    Last Post: September 19th, 12:47 PM
  3. Replies: 0
    Last Post: July 23rd, 09:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139