PHP code example of xparse / parser

1. Go to this page and download the library: Download xparse/parser 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/ */

    

xparse / parser example snippets


  use Xparse\Parser\Parser;
  use Xparse\Parser\RecursiveParser;
  
  # init Parser
  $parser = new Parser();

  # set expression to pagination links and initial page url
  $pages = new RecursiveParser(
       $parser,
       ["//*[@class='pagination']//a/@href"],
       ['https://github.com/search?q=xparse']
  );

  $allLinks = [];
  foreach($pages as $page){
    # set expression to fetch repository links
    $adsList = $page->value("//*[@class='repo-list-name']//a/@href")->all();
    # merge and remove duplicates
    $allLinks = array_values(array_unique(array_merge($allLinks, $adsList)));
  }
  print_r($allLinks);
 php
  $parser = new \Xparse\Parser\Parser();
  $title = $parser->get('http://funivan.com')->content('//*[@class="entry-title"]/a');
  print_r($title);
 php
  public function __invoke(callable $handler) : \Closure {
    return function (RequestInterface $request, array $options) use ($handler) {

      # some code

      return $handler($request, $options)->then(function (ResponseInterface $response) use ($request) {

        $response = $response->withHeader('X-GUZZLE-EFFECTIVE-URL', $request->getUri());
        
        # some code

        return $response;
      });
    };
  }