Programming Tips - PHP: do a `wget` in php

Date: 2010mar27 Language: php Q. PHP: do a `wget` in php A. There are several ways. You can shell out to wget. But for normal use here are some ways.
# Just use copy! function fetchUrl1(string $url, string $filename): bool { return copy($url, $filename); } # I prefer this one since you can tell if getting the URL failed # there was a permission (etc) problem locally. function fetchUrl2(string $url, string $filename): bool { if (($s = file_get_contents($url)) === false) return false; return file_put_contents($filename, $s); }
As I said, there are other ways.