Re: Why Does "function endElement($parser, $name)" Do This?



On Fri, 29 Feb 2008 05:57:02 -0500, Jerry Stuckle
<jstucklex@xxxxxxxxxxxxx> wrote:

maria wrote:
This is kind of strange.
I open a stream called $fh with name, say, "maria", before the
function below, and then I try to write into the file "maria" to no
avail! I keep getting the error:

"fwrite(): supplied argument is not a valid stream resource in ... ".

We can't use a stream to write into inside endElement?

Here is the function

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
fwrite($fh,$title);
printf("<dt><b><a
href='%s'>%s</a></b></dt>",trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

It is part of a PHP-program that reads RSS files and saves them with
certain format added. Everything else works fine.
This piece of code is not mine.
Please help!

maria


You haven't passed $fh to the function, so PHP doesn't have a value for it.

BTW - it's bad practice to use globals. When you call a function, pass
the values you need to that function. If you need to change the values,
pass them by reference.

Jerry,

How do I pass the stream $fh to that function?
I can do it in C++, but not in PHP.
Thanks!

maria
.



Relevant Pages

  • Re: Why Does "function endElement($parser, $name)" Do This?
    ... I open a stream called $fh with name, say, "maria", before the ... supplied argument is not a valid stream resource in ... ... You haven't passed $fh to the function, so PHP doesn't have a value for it. ... Jerry Stuckle ...
    (alt.php)
  • Re: Why Does "function endElement($parser, $name)" Do This?
    ... I open a stream called $fh with name, say, "maria", before the ... supplied argument is not a valid stream resource in ... ... You haven't passed $fh to the function, so PHP doesn't have a value for it. ... I thought that the function endElement takes only two arguments. ...
    (alt.php)
  • Why Does "function endElement($parser, $name)" Do This?
    ... This is kind of strange. ... I open a stream called $fh with name, say, "maria", before the ... supplied argument is not a valid stream resource in ... ... It is part of a PHP-program that reads RSS files and saves them with ...
    (alt.php)
  • Re: Why Does "function endElement($parser, $name)" Do This?
    ... I open a stream called $fh with name, say, "maria", before the ... supplied argument is not a valid stream resource in ... ... certain format added. ... It won't write into the stream $fh no matter what I try to write. ...
    (alt.php)
  • Re: Why Does "function endElement($parser, $name)" Do This?
    ... I open a stream called $fh with name, say, "maria", before the ... supplied argument is not a valid stream resource in ... ... BTW - it's bad practice to use globals. ...
    (alt.php)