Advertisement
Guest User

Parse price from vseinstrumenti.ru

a guest
May 17th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. /**
  2.  * Return parsed price value from $link page
  3.  * @param string $link
  4.  * @return float
  5.  */
  6. function getPrice( $link )
  7. {
  8.    $page = file_get_contents($link);
  9.  
  10.    if ( empty($page) )
  11.    {
  12.       return 0;
  13.    }
  14.  
  15.    if ( preg_match_all('#<meta itemprop="price" content="(\d+)">#iu', $page, $matches))
  16.    {
  17.       return floatval(array_shift($matches[1]));
  18.    }
  19.  
  20.    return 0;
  21. }
  22.  
  23. var_dump(getPrice('http://www.vseinstrumenti.ru/santehnika/svar-pay-app-plast-poliprop-trub/inforce/03-12-02/'));
  24. // Напечатает double(2859)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement