[英]delete “ ” in php
With this url http://www.google.com/ig/calculator?hl=fr&q=150euro=?dirhams , we can have a currency convert. 使用此网址http://www.google.com/ig/calculator?hl=fr&q=150euro=?dirhams ,我们可以进行货币转换。
This is the result : {lhs: "150 Euros",rhs: "1 691.50299 Moroccan dirhams",error: "",icc: true}
结果是:
{lhs: "150 Euros",rhs: "1 691.50299 Moroccan dirhams",error: "",icc: true}
I try to work with this result which looks like json. 我尝试使用看起来像json的结果。 So I use
json_decode
but it doesn't work. 所以我使用
json_decode
但它不起作用。
So I thought it looks like serilize/unserialize so I use unserialize
but it doesn't work. 所以我认为它看起来像是serilize / unserialize,所以我使用了
unserialize
但它不起作用。
Nervous, I used regexp and at the end I've got my value in dirhams with an
紧张,我使用了regexp,最后我有了一个带有
迪拉姆价值
because the value gets 4 numbers before the coma. 因为该值在昏迷前得到4个数字。
And this
而这个
I can't delete it ! 我无法删除它! I try preg_replace, str_replace... no ways !
我尝试preg_replace,str_replace ...没办法!
This is the function 这是功能
I just want to get the "dirhams value", only the numbers, as a float 我只想获取“迪拉姆值”(仅数字)作为浮点数
Anyone can help me ? 有人可以帮助我吗?
public function convertDirhams($prix, $monnaie_base = 'euro', $monnaie_convert = 'dirhams')
{
$prix = urlencode($prix);
$monnaie_base = urlencode($monnaie_base);
$monnaie_convert = urlencode($monnaie_convert);
$url = "http://www.google.com/ig/calculator?hl=fr&q=$prix$monnaie_base=?$monnaie_convert";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
/*$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];*/
$data = preg_replace('/ /','',$rawdata);
$data = explode(':',$data);
$data = preg_replace('/"/','',$data[2]);
$data = preg_replace('/Moroccandirhams,error/isu','',$data);
$prix_final = preg_replace("/&#?[a-z0-9]{2,8};/i","",$data);
//echo $prix_final;
return (float)trim($data);
}
I too was stuck with this issue when i used google currency converter. 当我使用Google Currency Converter时,我也一直被这个问题困扰。 I tried many things and nothing worked for me.
我尝试了很多事情,对我没有任何帮助。 Finally i found this piece of code.
终于我找到了这段代码。
You can try with : 您可以尝试:
$number = preg_replace('/[^a-z0-9.]/', '', $number);
or 要么
$number = ereg_replace("[^A-Za-z0-9.]", "", $number );
Both works perfectly fine. 两者都工作得很好。
ereg_replace()
is depreciated function in php5.3. ereg_replace()
是php5.3中已弃用的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.