Skip to content

kldeepak/ElementFinder

 
 

Repository files navigation

ElementFinder

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Extract data from html with elegant xpath/css expressions and prepare data with regexp in single line.

Install

Via Composer

$ composer require xparse/element-finder

Usage

  $page = new ElementFinder($html);
  $title = $page->value('//title')->getFirst();  
  echo $title;  

Advanced usage with regexp

$page = new \Xparse\ElementFinder\ElementFinder('<html>
 
<div class="tels">
    044-12-12,
    258-16-16
</div>

<div class="tels">
    (148) 04-55-16
</div>
 
 </html>');

  $tels = $page->value('//*[@class="tels"]')->split('!,!')->replace("![^0-9]!");
  print_r($tels);
  
  /* 
    [0] => 0441212
    [1] => 2581616
    [2] => 148045516
  */
  

Css selectors

Read this document. Using css selectors.

Testing

  ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

Xpath info

License

The MIT License (MIT). Please see License File for more information.

About

Fetch data from HTML and XML via xpath and prepare it with regexp

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 97.9%
  • HTML 2.1%