Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

you can also use preg_replace,like

 $result = preg_replace('/[^\sa-z]/i', '', $string);

this removes every characters and whitespace from your string

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top