Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help on fputs warning message
Old 08-26-2004, 08:32 AM Help on fputs warning message
Novice Talker

Posts: 11
Trades: 0
Hello to all,

I'm parsing a XML document into HML using PHP. The problem is that when I run the PHP script I get severals warnings messages when the fputs function in use, like this one:

Warning: fputs(): supplied argument is not a valid stream resource in /srv/www/htdocs/my_examples/script.php on line 50

If I use the echo sentence to write the result on the screen, instead of witting to a local file with fputs, no error or warning messages are reported, but the problem is that I have to use the fputs funtion to make my on html file for later use.

Do you have any ideas to solve this problem? I hope you can help me?

Many thanks.

MY PHP SCRIPT to parse the xml file
************************************************** ************************************************
PHP Code:
<?php
    
//Initialize Parser
    
$parser=xml_parser_create();
    
//Specify Handlers to start and ending tag
    
xml_set_element_handler($parser"start_element""end_element");
    
//Data Handler
    
xml_set_character_data_handler($parser"character_data");
    
//Open the Data File 
    
$fp=fopen("script.xml""r") ;

// Give a name to the html file
    
$createdname='xFactura';
    
$date=date("Ymd");
    
$time=date("His");
    
$source_file=$createdname.$date.$time.".html";
    
$name_html=$source_file;    
//Open the html file for writing
    
$fphtml=fopen($name_html,"a");
//Write a line.
    
fputs($fphtml,'<html><body>');
//Small delay to write the data 
    
usleep(10000);

//read the XML file Data
    
while ($data=fread($fp4096))
    {
        
xml_parse($parser$data,feof($fp)) or 
            die (
sprintf("XML Error: %s at line %d"
                
xml_error_string(xml_get_error_code($parser)),
                
xml_get_current_line_number($parser)));
    }
    
xml_parser_free($parser);

function 
start_element($parser$element_name$element_attrs)
{
    switch(
$element_name)
    {
    case 
"SENDER":
        
//echo ('<table border="1"><tbody>');
    
fputs($fphtml,'<table border="1"><tbody>');usleep(10000);
    break; 
    case 
"SENDER_NAME":
        
//echo ('<tr><td colspan="4">');
        
fputs($fphtml,'<tr><td colspan="4">');usleep(10000);
    break; 
    case 
"ADDRESS":
        
//echo ('<tr><td colspan="4">');
        
fputs($fphtml,'<tr><td colspan="4">');usleep(10000);
    break; 
    case 
"CP_SENDER":
        
//echo "<tr><td>";
        
fputs($fphtml,'<tr><td>');usleep(10000);
    break;     
    case 
"CYTY":
        
//echo "<td>";
    
fputs($fphtml,'<td>');usleep(10000);
    break;
    case 
"REGION":
        
//echo "<td>(";
        
fputs($fphtml,'<td>(');usleep(10000);
    break; 
    case 
"CIF_NUMBER":
        
//echo ('<tr><td colspan="4">CIF:');
        
fputs($fphtml,'<tr><td colspan="4">CIF:');usleep(10000);
    break; 
    case 
"PHONE_NUMEBR":
        
//echo "<tr><td></td><td>Tel:";    
    
fputs($fphtml,'<tr><td></td><td>Tel:');usleep(10000);
    break;
    case 
"FAX_NUMBER":
        
//echo "<td>Fax:";
    
fputs($fphtml,'<td>Fax:');usleep(10000);
    break;
    }
}
function 
end_element($parser$element_name)
{
    switch(
$element_name)
    {
    case 
"SENDER":
        
//echo "</tbody></table>";
        
fputs($fphtml,'</tbody></table>');usleep(10000);
    break; 
    case 
"SENDER_NAME":
        
//echo "</td></tr>";
        
fputs($fphtml,'</td></tr>');usleep(10000);
    break; 
    case 
"ADDRESS":
        
//echo "</td></tr>";
        
fputs($fphtml,'</td></tr>');usleep(10000);
    break; 
    case 
"CP_SENDER":
        
//echo "</td>";
        
fputs($fphtml,'</td>');usleep(10000);
    break;     
    case 
"CYTY":
        
//echo "</td>";
    
fputs($fphtml,'</td>');usleep(10000);
    break;
    case 
"REGION":
        
//echo ")</td><td></td></tr>";
        
fputs($fphtml,')</td><td></td></tr>');usleep(10000);
    break; 
    case 
"CIF_NUMBER":
        
//echo "</td></tr>";
        
fputs($fphtml,'</td></tr>');usleep(10000);
    break; 
    case 
"PHONE_NUMBER":
        
//echo "</td>";
    
fputs($fphtml,'</td>');usleep(10000);
    break;
    case 
"FAX_NUMBER":
        
//echo "</td><td></td></tr>";    
    
fputs($fphtml,'</td><td></td></tr>');usleep(10000);
    break;
    }
}
function 
character_data($parser,$data)
{
    echo 
$data;
}
fputs($fphtml,'</body></html>');usleep(10000);
fclose($fphtml);
?>
************************************************** *************************************************
MY XML FILE

<?xml version="1.0"?>
<document>
<sender>
<sender_name>Albert Einstein</sender_name>
<address>any address</address>
<city>London</city>
<region>Europe</region>
<cp_sender>23345</cp_sender>
<cif_number>2356776</cif_number>
<phone_number>23456789</phone_number>
<fax_number>45678943</fax_number>
</sender>
</document>
aufkes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2004, 10:27 AM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Well it would seem to me that the file is not being created. Do you have proper permisions on the directory in which the script is attempting to create the file?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 04:22 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
I only glanced at it, but it looks like you're trying to create the file with the 'a' (append) flag. Use the 'w' (write) flag instead....
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-27-2004, 06:42 AM
Novice Talker

Posts: 11
Trades: 0
I forget to put
global $fphtml;
as the first line in each of my functions. Otherwise I can't access the value
Many thanks for answering. Now is working
aufkes is offline
Reply With Quote
View Public Profile
 
Old 08-27-2004, 07:48 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
lol! Me and winky should both be shot for not seeing that one.
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-27-2004, 08:40 AM
Novice Talker

Posts: 11
Trades: 0
Me first!!!!!

Thanks anyway.
aufkes is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help on fputs warning message
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27603 seconds with 12 queries