Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts

    crazy parse error

    I'm getting a parse error for this line of code:

    PHP Code:
    if (strpos($file_line, '<?xml) !== false)
    And I can;t figure out why...I tried changing the single quotes to double quotes (for every strpos() call), but that just gave me a parse error for this line:

    PHP Code:
    ?> 
    The relevent code is as follows:

    PHP Code:
    <?

    // Start of functions

    function readThisFile($xml_file)
    {
        if(!
    file_exists($xml_file))
        {
            die(
    "The data file does not exist.");
        }

        
    chmod($xml_file0777);

        if(!
    $handle fopen($xml_file,"r"))
        {
            die(
    "There was a problem opening the data file.");
        }

        while(!
    feof($handle))
        {
            
    $file_line fgets($handle4096);

            if (
    strpos($file_line'<?xml') !== false)
            {
                continue;
            }
            elseif (
    strpos($file_line'<!DOCTYPE') !== false)
            {
                continue;
            }
            elseif (
    strpos($file_line'<reference>') !== false)
            {
                continue;
            }
            elseif (
    strpos($file_line'</contact>') !== false)
            {
                continue;
            }
            elseif (
    strpos($file_line'</reference>') !== false)
            {
                continue;
            }

            
    $content .= $file_line;
        }

        
    fclose($handle);

        return 
    $content;
    }


    function 
    getElementInfo($element_name,$data_text)
    {
        if (empty(
    $data_text))
        {
            return 
    false;
        }

        
    $pattern "/<" $element_name ">.*<\/" $element_name ">/";

        
    preg_match($pattern$data_text$matches);

        
    $pattern2 "<" $element_name ">";
        
    $matches[0] = str_replace($pattern2""$matches[0]);

        
    $pattern3 "</" $element_name ">";
        
    $matches[0] = str_replace($pattern3""$matches[0]);

        return 
    trim($matches[0]);
    }

    ?>
    Plus, I;ve already used this code once before, and had no problems.

    Anyone see what the problem is here? thanks.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    You forgot to include the actual error. It all works fine for me, but I don't have shorttags enabled and that might be part of the issue. Try separating the tag:

    if (strpos($file_line, '<' . '?xml') !== false)

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To my knowledge, tags should always be able to be printed in a string regardless of what tags are enabled. Seeing the error would help.

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    it's just a plain parse error, nothing special or helpful in there:

    Parse error: parse error in /var/www/html/blah/blah/modify_contact.php on line 107
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    did you try the idea ralph l mayo suggested? to my knowledge it wont help becuase strings should be treated ok, but its worth a go as I cant see anything wrong with your code.

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by ralph l mayo
    You forgot to include the actual error. It all works fine for me, but I don't have shorttags enabled and that might be part of the issue. Try separating the tag:

    if (strpos($file_line, '<' . '?xml') !== false)
    Tried this, and it doesn;t help.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by missing-score
    did you try the idea ralph l mayo suggested? to my knowledge it wont help becuase strings should be treated ok, but its worth a go as I cant see anything wrong with your code.
    just tried and it was a no-go...

    There is some PHP, HTML and javascript that comes before these functions, could they somehow be causing the error....but I can;t see how really...I can post it here if you think it will help
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877
    I can post it here if you think it will help
    It might. That line all by itself does not complain on my server, when I replace $file_line with a short text string.
    I'm thinking it might have to do with parsing the actual file handle - maybe something with character set. Can we see a sample of the XML file too? Does it happen consistently with different source xml files?

  • #9
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    sample of xml file:

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE reference SYSTEM "contact_reference.dtd">
    <reference>
    	<contact>
    		<firstname>blah</firstname>
    		<lastname>blah</lastname>
    		<business>blah</business>
    		<email>blah</email>
    		<website>blah</website>
    		<phone>blah</phone>
    		<address>
    			<street>blah</street>
    			<city>blah</city>
    			<state>blah</state>
    			<zip>blah</zip>
    			<country>blah</country>
    		</address>
    	</contact>
    	<contact>
    		<firstname>blah</firstname>
    		<lastname>blah</lastname>
    		<business>blah</business>
    		<email>blah</email>
    		<website>blah</website>
    		<phone>blah</phone>
    		<address>
    			<street>blah</street>
    			<city>blah</city>
    			<state>blah</state>
    			<zip>blah</zip>
    			<country>blah</country>
    		</address>
    	</contact>
    </reference>
    dtd file:

    Code:
    <?xml version="1.0"?>
    <!ELEMENT reference (contact*)>
    <!ELEMENT contact (firstname,lastname,business,email,website,phone,address)>
    <!ELEMENT firstname (#CDATA)>
    <!ELEMENT lastname (#CDATA)>
    <!ELEMENT business (#CDATA)>
    <!ELEMENT email (#CDATA)>
    <!ELEMENT website (#CDATA)>
    <!ELEMENT phone (#CDATA)>
    <!ELEMENT address (street,city,state,zip,country)>
    <!ELEMENT street (#CDATA)>
    <!ELEMENT city (#CDATA)>
    <!ELEMENT state (#CDATA)>
    <!ELEMENT zip (#CDATA)>
    <!ELEMENT country (#CDATA)>
    And this is the only xml file i have available that is written for this dtd...

    hope this helps..

    Edit: also, please remember that I used the above PHP code in a different file to parse the same xml document, and IT WORKED.

    It's just not working in this particular file....Here is the entire file:

    PHP Code:
    <?

    $c_name 
    $_GET['c_name'];

    if (
    strpos($c_name',') !== false)
    {
        
    $c_name_array explode(","$c_name);
        
    $ln trim($c_name_array[0]);
        
    $fn trim($c_name_array[1]);
    }
    else
    {
        
    $fn trim($c_name);
        
    $ln "";
    }

    $uri rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

    $xml_file $_SERVER['DOCUMENT_ROOT'] . "/" $uri "/" "contact_reference.xml";

    $content2 readThisFile($xml_file);

    $contact_array2 preg_split("/<contact>/"$content2);
    unset(
    $contact_array2[0]);

    foreach (
    $contact_array2 as $key => $val)
    {
        
    $the_fn getElementInfo("firstname",$val);
        
    $the_ln getElementInfo("lastname",$val);

        if (
    $ln == $the_ln && $fn == $the_fn)
        {
            
    $b_name getElementInfo("business",$val);
            
    $the_email getElementInfo("email",$val);
            
    $the_website getElementInfo("website",$val);'
            $the_phone = getElementInfo("phone",$val);
            $the_street = getElementInfo("street",$val);
            $the_city = getElementInfo("city",$val);
            $the_state = getElementInfo("state",$val);
            $the_zip = getElementInfo("zip",$val);
            $the_country = getElementInfo("country",$val);

            break;
        }
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">

    <head>

    <title>Modify Contact</title>

    <link rel="stylesheet" type="text/css" href="contact_reference.css" />

    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

    <body>

    <form action="contact_reference.php" method="post">

        <p>First Name: <input type="text" name="first_name" size="25" value="<? echo $the_fn; ?>"></p>
        <p>Last Name: <input type="text" name="last_name" size="25" value="<? echo $the_ln; ?>"></p>
        <p>Business Name: <input type="text" name="business_name" size="25" value="<? echo $b_name; ?>"></p>
        <p>E-mail Address: <input type="text" name="email" size="25" value="<? echo $the_email; ?>"></p>
        <p>Website Address: <input type="text" name="website" size="25" value="<? echo $the_website; ?>"></p>
        <p>Phone Number: <input type="text" name="phone" size="25" value="<? echo $the_phone; ?>"></p>
        <p>Street Address: <input type="text" name="street" size="25" value="<? echo $the_street; ?>"></p>
        <p>City: <input type="text" name="city" size="25" value="<? echo $the_city; ?>"></p>
        <p>State/Region: <input type="text" name="state" size="20" value="<? echo $the_state; ?>"></p>
        <p>Postal Code: <input type="text" name="zip" size="15" value="<? echo $the_zip; ?>"></p>
        <p>Country: <input type="text" name="country" size="25" value="<? echo $the_country; ?>"></p>

        <p style="text-align:center"><input type="submit" name="add_submit" value="Update Contact"><input type="reset" value="Reset Form"></p>

    </form>

    </body>

    </html>

    <?

    // Start of functions

    function readThisFile($xml_file)
    {
        if(!file_exists($xml_file))
        {
            die("The data file does not exist.");
        }

        chmod($xml_file, 0777);

        if(!$handle = fopen($xml_file,"r"))
        {
            die("There was a problem opening the data file.");
        }

        while(!feof($handle))
        {
            $file_line = fgets($handle, 4096);

            if (strpos($file_line, '
    <?xml') !== false)
            {
                continue;
            }
            elseif (strpos($file_line, '
    <!DOCTYPE') !== false)
            {
                continue;
            }
            elseif (strpos($file_line, '
    <reference>') !== false)
            {
                continue;
            }
            elseif (strpos($file_line, '
    </contact>') !== false)
            {
                continue;
            }
            elseif (strpos($file_line, '
    </reference>) !== false)
            {
                continue;
            }

            
    $content .= $file_line;
        }

        
    fclose($handle);

        return 
    $content;
    }


    function 
    getElementInfo($element_name,$data_text)
    {
        if (empty(
    $data_text))
        {
            return 
    false;
        }

        
    $pattern "/<" $element_name ">.*<\/" $element_name ">/";

        
    preg_match($pattern$data_text$matches);

        
    $pattern2 "<" $element_name ">";
        
    $matches[0] = str_replace($pattern2""$matches[0]);

        
    $pattern3 "</" $element_name ">";
        
    $matches[0] = str_replace($pattern3""$matches[0]);

        return 
    trim($matches[0]);
    }

    ?>
    Last edited by chump2877; 05-01-2006 at 05:30 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #10
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    LOL, I wasn;t using my color coded editor...now the error is plain as day:
    PHP Code:
            $the_website getElementInfo("website",$val);
            
    $the_phone getElementInfo("phone",$val); 

    grrrr
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #11
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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