Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]preg_match_all - problem
casperii
post 2.04.2020, 15:12:10
Post #1





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

Ostrzeżenie: (0%)
-----


panowie , przejdę od razu do rzeczy, kod:

  1. public function __construct($url = 'http://api.nbp.pl/api/exchangerates/tables/A/2020-04-02')
  2. {
  3. $this->_url = $url;
  4. }
  5.  
  6.  
  7. $html = file_get_contents($this->_url . '');
  8. $pattern = '/\/tables\/A\/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/';
  9. preg_match_all($pattern, $html, $matches);
  10. if (!isset($matches[0][0])) {
  11. throw new Exception('Unable to find XML filepath!');
  12. }
  13.  
  14. $xml = file_get_contents($this->_url . $matches[0][0]);
  15. if (!file_exists($this->_cache)) {
  16. if (!mkdir($this->_cache)) {
  17. throw new Exception('Unable to create cache directory!');
  18. }
  19. }
  20. if (!file_put_contents($filepath, $xml)) {
  21. throw new Exception('Unable to save file in cache directory!');
  22. }
  23. return $xml;


Niestety zwraca throwa Unable to find XML filepath , ktoś podpowie ? Chodzi o pobranie "2020-04-02" i zapisanie w katalogu na ftp.

Ten post edytował casperii 2.04.2020, 15:14:30
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 14:42