/** * Extract data from the downloaded content. * * @param $html * @param $status * @param $options * * @return array */ protected function process($html, $status, $options) { $data = []; $data['laws'] = []; $page = crawler($html); $last_pager_link = $page->filterXPath('//*[@id="page"]/div[2]/table/tbody/tr[1]/td[3]/div/div[2]/span/a[last()]'); $data['page_count'] = $last_pager_link->count() ? preg_replace('/(.*?)([0-9]+)$/u', '$2', $last_pager_link->attr('href')) : 1; $page->filterXPath('//*[@id="page"]/div[2]/table/tbody/tr[1]/td[3]/div/dl/dd/ol/li')->each(function (Crawler $node) use(&$data) { $url = $node->filterXPath('//a')->attr('href'); $id = preg_replace('|/laws/show/|u', '', shortURL($url)); $raw_date = $node->filterXPath('//font[@color="#004499"]')->text(); $date = $this->parseDate($raw_date, "Date has not been found in #{$id} at text: " . $node->text()); $data['laws'][$id] = ['id' => $id, 'date' => $date]; }); return $data; }
.page-header { font-size: 1.8em; } </style> </head> <body> <div id="main"> <div class="container"> <h1 class="page-header">Fazer encurtador de url com PHP e migre.me</h1> <?php include_once "short-url.php"; $urlAntes = "http://nandomoreira.me/2012/12/22/fazer-encurtador-de-url-com-php-e-migre-me/"; if (!isset($_SESSION['shorturl']) || empty($_SESSION['shorturl'])) { $url = shortURL($urlAntes); $_SESSION['shorturl'] = $url; } $shorturl = $_SESSION['shorturl']; ?> <p>URL Normal: <a href="<?php echo $urlAntes; ?> "><?php echo $urlAntes; ?> </a> </p> <p>URL Curta: <a href="<?php echo $shorturl; ?>
$sel->execute(); $count = $sel->rowCount(); //Restock DB if only one result letft. if ($count == "0") { $me = results(); $flickr = json_decode($me, TRUE); foreach ($flickr['photos']['photo'] as $photo) { $cat = $photo['url_m']; insert2db($cat); } } //Select Flickr url $getcat = $pdo->prepare('SELECT * FROM `cats` LIMIT 0 , 1'); $getcat->execute(); $result = $getcat->fetch(PDO::FETCH_ASSOC); $caturl = $result['url']; //Convert to biy.ly $newurl = shortURL($caturl); //Send SMS $message = "Hello Cat Lady - here is today's Cat Picture " . $newurl . ""; echo $message; if ($number != "test") { sendsms($number, $message); } //Remove flickr url removecat($caturl); ?>
for ($i = 0; $i < sizeof($classes["Data"]); $i++) { if (!isset($classes["Data"][$i]["MAR_short_url"])) { $guid = $classes['Data'][$i]['cobalt_classId']; $shorturl = shortURL(CLASS_URL . $guid); $RamcoAPI->clearVars(); $RamcoAPI->setOperation("UpdateEntity"); $RamcoAPI->setGUID($guid); $RamcoAPI->setEntity("cobalt_class"); $RamcoAPI->setAttributeValues("MAR_short_url={$shorturl}"); $json = $RamcoAPI->sendMessage(); $class_result = json_decode($json, true); } if (!isset($classes["Data"][$i]["MAR_checkinlink"])) { echo "wheres my checkin"; $guid = $classes['Data'][$i]['cobalt_classId']; $shorturl_mobile = shortURL(MOBILE_CHECKIN_LINK . "?guid=" . $guid . "&type=class"); echo "<br>Short Mobile Checkin link: {$shorturl_mobile} <br>"; $RamcoAPI->clearVars(); $RamcoAPI->setOperation("UpdateEntity"); $RamcoAPI->setGUID($guid); $RamcoAPI->setEntity("cobalt_class"); $RamcoAPI->setAttributeValues("MAR_checkinlink={$shorturl_mobile}"); $json = $RamcoAPI->sendMessage(); $class_mobile_result = json_decode($json, true); pretty_print($class_mobile_result); } } } // Output a message at the end of the file echo "<br>End of file.<br />"; function shortURL($longURL)