HomeBrew fatal error: 'pcre2.h' file not found
ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre
17 февраля 2021, 00:04
ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre
<?php function slugify($string) { $translit = "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();"; $string = transliterator_transliterate($translit, $string); $string = preg_replace('/[-\s]+/', '-', $string); return trim($string, '-'); } echo slugify("Я люблю PHP!");
$file = new SplFileObject("file.txt"); while (!$file->eof()) { echo $file->fgets(); }
function lines($filename) { $file = new SplFileObject($filename); while (!$file->eof()) { yield $file->fgets(); } } foreach (lines('German.txt') as $line) { echo $line; }
<?php function getUuid() { // http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid // by Andrew Moore (http://www.php.net/manual/en/function.uniqid.php#94959) return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); }
<?php $result = (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => 321]); echo $result; // триста двадцать один $result = (new \MessageFormatter('ru-RU', '{n, spellout,%spellout-cardinal-feminine}'))->format(['n' => 321]); echo $result; // триста двадцать одна
<?php $formatter = new IntlDateFormatter('ru_RU', IntlDateFormatter::FULL, IntlDateFormatter::FULL); $formatter->setPattern('d MMMM YYYY, HH:mm'); echo $formatter->format(new DateTime('2015-01-01 01:01:01')); //1 января 2015, 01:01
{ "require": { "jonnyw/php-phantomjs": "3.*", "symfony/dom-crawler": "3.*", "symfony/css-selector": "3.*" }, "config": { "bin-dir": "bin" }, "scripts": { "post-install-cmd": [ "PhantomInstaller\\Installer::installPhantomJS" ], "post-update-cmd": [ "PhantomInstaller\\Installer::installPhantomJS" ] } }Скачаем все зависимости
php composer.phar installНу и сам парсинг index.php
<?php require __DIR__ . '/vendor/autoload.php'; $client = \JonnyW\PhantomJs\Client::getInstance(); $request = $client->getMessageFactory()->createRequest('http://superdeals.aliexpress.com/en?spm=2114.11010108.21.1.v65LIL', 'GET'); $response = $client->getMessageFactory()->createResponse(); $client->send($request, $response); $html = $response->getContent(); $crawler = new \Symfony\Component\DomCrawler\Crawler($html); $div = $crawler->filter('div.pro-msg'); if($div) { echo $div->first()->text(); }Если выполнить php index.php можно увидеть, что фантом скачал страницу и выполнил javascript код
Today Only Boy's Coat > Synthetic leather> Motor jacket style> Available in black and red share: vk pinterest facebook Twinner Google+ Email Sign in and share the website for a chance to get Points, which you can then convert to coupons. US $9.74 US $32.48 / piece | 70% Off 0486Left Buy Now
<?php function getRows($file) { $handle = fopen($file, 'rb'); if ($handle === false) { throw new Exception(); } while (feof($handle) === false) { yield fgetcsv($handle); } fclose($handle); } foreach (getRows('data.csv') as $row) { print_r($row); }