Currently working with PHP Simple HTML DOM Parser and come across a very strange scenario.
I have a set of urls which i am crawling and using the following to get the info i need:
foreach($urls as $url) {
$html = file_get_html($url);
foreach($html->find('.product4block') as $article) {
$item['title'] = $article->find('.product4text', 0)->plaintext;
$item['link'] = $article->find('.product4text a', 0)->href;
$item['price'] = $article->find('.product_price', 0)->plaintext;
$data[] = $item;
}
}
I then get a result like the following, which is what i need:
Array
(
[0] => Array
(
[title] => title 0
[link] => link 0
[price] => £26.99
)
[1] => Array
(
[title] => title 1
[link] => link 1
[price] => £27.99
)
[2] => Array
(
[title] => title 2
[link] => link 2
[price] => £30.99
)
)
I then loop through the data adding it to my database.
foreach($data as $result){
//insert data here//
}
I then need to remove the £ symbol from the price. Which i am simply doing a str_replace like this:
$price = str_replace('£', '', $result['price']);
For some strange reason the £ is not getting removed. Im not sure if its the dom parser causing issues, or if str_replace just isn't working for some reason.
Any reason why this wouldn't work?
str_replaceseems to be working for me, just as a check could you try altering thestr_replaceto remove another character in the price string. if that removes it then the issue is that the two£characters aren't the same for some reason, whether that's due to some form of character encoding I'm not 100% sure.