/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { DB::table('landingpagewordcloud')->where('landing_page_urls_id', $id)->delete(); return Response::json(LandingPageUrl::destroy($id)); }
public function scrapeLandingPage($landingpageid) { DB::table('landingpagewordcloud')->where('landing_page_urls_id', $landingpageid)->delete(); $snoopy = new Snoopy(); $snoopy->fetchtext(LandingPageUrl::find($landingpageid)->landingpageurl); $body = $snoopy->results; $body = strtolower($body); //$body = strip_tags($body); $body = html_entity_decode($body); $body = preg_replace('!\\s+!', ' ', $body); // replace continuous space by one spaces $body = preg_replace('/[^A-Za-z0-9 _\\-\\+\\&]/', '', $body); // delete non alpha numeric and _ - + & chars ////$body = preg_replace( '/[^[:print:]]/', '', $body ); $body = utf8_encode($body); $tagArray = []; $allWordsArray = explode(" ", $body); foreach ($allWordsArray as $k => $v) { $v = trim($v); if (!($v == '' || $v == ' ')) { if (isset($tagArray[$v])) { $tagArray[$v]++; } else { $tagArray[$v] = 1; } } } $insertData = []; foreach ($tagArray as $word => $count) { $insertData[] = array('word' => $word, 'freq' => $count, 'landing_page_urls_id' => $landingpageid); } DB::table('landingpagewordcloud')->insert($insertData); return Response::json($tagArray); }