PHP code example of gkueny / html-meta-crawler-bundle

1. Go to this page and download the library: Download gkueny/html-meta-crawler-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gkueny / html-meta-crawler-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new GK\HtmlMetaCrawlerBundle\GKHtmlMetaCrawlerBundle(),
        );

        // ...
    }

    // ...
}




namespace GK\HtmlCrawlerBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class DefaultController
 *
 * @package GK\HtmlCrawlerBundle\Controller
 */
class DefaultController extends Controller
{
    /**
     * @Route("/", name="crawler_homepage")
     *
     * @return Response
     */
    public function indexAction()
    {

        $url = 'http://gkeny.fr';
        
        try {
            $myMetasFb = $this->get("gk.html_meta_crawler")->getMetaFacebook($url);
        
            $myMetasTw = $this->get("gk.html_meta_crawler")->getMetaTwitter($url);
        
            $myMetasBasic = $this->get("gk.html_meta_crawler")->getBasicMeta($url);
        
            $myMetasAll = $this->get("gk.html_meta_crawler")->getAllMeta($url);
        
        } catch (Exception $e) {
            echo $e->getMessage();
        
            exit;
        }
        
        
        echo "<p> Facebook : <br/>";
        
        foreach ($myMetasFb as $myMeta ) {
            echo $myMeta['property'] . " = " . $myMeta['content'] . '<br/>';
        }
        
        echo "</p>";
        
        
        echo "<p> Twitter : <br/>";
        
        foreach ($myMetasTw as $myMeta ) {
            echo $myMeta['name'] . " = " . $myMeta['content'] . '<br/>';
        }
        
        echo "</p>";
        
        
        echo "<p> Basic : <br/>";
        
        foreach ($myMetasBasic as $myMeta ) {
            print_r($myMeta);
            echo "<br/>";
        }
        
        echo "</p>";
        
        echo "<p> All : <br/>";
        
        foreach ($myMetasAll as $myMeta ) {
            print_r($myMeta);
            echo "<br/>";
        }
        
        echo "</p>";
        
        exit;
        
            
    }
}