I'm trying to get the text that contains certain tags within the HTML
on a page, I'm using simple_html_dom.php
that I thought was good for this. Without more I leave an example of my problem.
This is the function in php
require('simple_html_dom.php');
function precioExito($url){
$html = new simple_html_dom();
$html->load_file($url);
$posts = $html->find('p[class=price offer]');
foreach($posts as $post) {
$resultado = str_replace ( ".0", '', $post);
break;
}
return $resultado;
}
What I do is that I call this function if I do an echo to that value it shows me the value on the screen (View image)
But when that value that returns to me I send it to the BD, this is what saves me in the BD. (View image)
As you can see, it's bringing me the whole HTML tag and not just the value.
QUESTION
How can I get only the value of this tag in order to save it?
this is because you are posting the whole html element..
what you need to do is parse its innerText
foreach($posts as $post) {
$resultado = str_replace ( ".0", '', $post->innertext);
break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.