Search code examples
phpjqueryphpquery

How to get specified content from indside a div


How to get content (a specified content) from inside a #div.

I have form like:

<?php
require_once('phpQuery/phpQuery.php');
$key-one = $_POST['key01'];
$html = file_get_contents('http://google.com/search?q='.$key-one.'');
phpQuery::newDocumentHTML($html);
$result01 = pq('div#resultStats');
?>

<body>
<form name="form1" method="post" action="1.php">
    <input type="text" name="key01"><br>
    <input type="submit" name="Submit" value="Submit">
</form>
</body>

I got result like:

About 1,570,000,000 results

But I only want

1,570,000,000

Thanks in advance.


Solution

  • You can use PHP str_replace.

    Assuming $result01 displays About 1,570,000,000 results:

    $result01 = str_replace("About ","",$result01);
    $result01 = str_replace(" results","",$result01);
    

    After these changes, echo $result01 will display 1,570,000,000.