PHP code example of kolter / csselectortranslator

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

    

kolter / csselectortranslator example snippets


use Kolter\CsselectorTranslator\CsselectorTranslator;

$query = "p.class1.class2.class3 > div[href^=https],img:first-child

$translator = new CsselectorTranslator();
$elements = $translator->parse();
// This will return an array of Element
echo $elements[0];
// Output: "p.class1.class2#id>div[href^=https],img"
// Element 0 is the p tag but the __toString() method will output the conection 
//between elements so it will show the whole selector
$element[0]->getClasses();
// Output: ['class1','class2']
$elements[0]->getId();
// Output: "id"