Re: Need eregi() help
| From: | Lars Torben Wilson | Date: | Fri, 01 Feb 2002 21:52:22 +0000 |
| Subject: | Re: Need eregi() help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83197@lists.php.net to get a copy of this message | ||
On Fri, 2002-02-01 at 13:28, Robby wrote:
> I am using this code below but it does not work (php in installed and
> working proplely):
You should provide a bit more information than "it's not working".
It helps immensely to know exactly *how* it isn't working. That
said, here's what sprang immediately to mind from the code below:
> <?php
>
> $file=fopen("http://somedomain/time.html",
> "r");
> if (!$file)
>
> echo "error when connect\n";
> exit;
> }
> $line = fread ($file, filesize ($file));
^^^^^^^^^^^^^^^^
Two things: 1) filesize() takes a filename, not a file descriptor
resource, as an argument; and 2) filename() doesn't work on remote
files. Check the manual page for more information:
http://www.php.net/manual/en/function.filesize.php
> eregi("^{<font color=green><b>}{.*}{</b></font>}$", $line,
> $out)
First, you need a semicolon at the end of the line--but I think that's
just a typo. ;)
Second: unless you're actually searching for curly braces, remove them.
They are special characters in regexes and if you're going to include
them, they'll need to be escaped.
Third: I gather that you're trying to get the content of the bold tag
here--if so, you'll need to encompass the '.*' with parentheses, so that
its value is copied into $out.
Ultimately, your line should look something like the one below:
if (eregi("^<font color=green><b>(.*)</b></font>$", $line, $out))
{
print_r($out);
} else {
echo "Failed\n";
}
Hope this helps,
Torben
> echo "$out[1]";
> fclose($file);
> ?>
>
>
> Robby
--
Torben Wilson <torben@php.net>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506