PHP code example of scarlett / lshw-parser

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

    

scarlett / lshw-parser example snippets


use Scarlett\LshwParser\Parser;

$xmlContent = file_get_contents('path/to/lshw-output.xml');
$parser = new Parser($xmlContent);

// Get system memory information
$memory = $parser->getSystemMemory();
echo $memory->getProperty('description')->getFirstValue();

// Get CPU information
$cpuInfo = $parser->getCpuInfo();
echo $cpuInfo->getProperty('vendor')->getFirstValue();

use Scarlett\LshwParser\Parser;

$xmlContent = file_get_contents('path/to/lshw-output.xml');
$parser = new Parser($xmlContent);

// Filter nodes with AND logic
$results = $parser->parseByProperties(['class' => 'processor', 'vendor' => 'Intel Corp.'], 'and');
foreach ($results as $result) {
    echo $result->getProperty('description')->getFirstValue();
}

// Filter nodes with OR logic
$results = $parser->parseByProperties(['class' => 'processor', 'vendor' => 'AMD'], 'or');
foreach ($results as $result) {
    echo $result->getProperty('description')->getFirstValue();
}

use Scarlett\LshwParser\Parser;

$xmlContent = file_get_contents('path/to/lshw-output.xml');
$parser = new Parser($xmlContent);

$results = $parser->searchNodesByFilter(function($properties) {
    return isset($properties['vendor']) && $properties['vendor'] === 'Intel Corp.';
});

foreach ($results as $result) {
    echo $result->getProperty('description')->getFirstValue();
}