"& nbsp;" php-da

With this url http://www.google.com/ig/calculator?hl=fr&q=150euro=?dirhams, we can have a currency convert.

This is the result : {lhs: "150 Euros",rhs: "1 691.50299 Moroccan dirhams",error: "",icc: true}

Men jsonga o'xshash natija bilan ishlashga harakat qilaman. Shuning uchun json_decode dan foydalanaman, lekin u ishlamayapti.

Ya'ni, unserialize dan foydalanayotganimda serilize/unserialize kabi ko'rinadi, lekin u ishlamaydi.

Nervous, I used regexp and at the end I've got my value in dirhams with an   because the value gets 4 numbers before the coma.

And this   I can't delete it ! I try preg_replace, str_replace... no ways !

Bu funksiya

Men faqat "dirhamlarning qiymatini" olishni istayman, faqat raqamlar float sifatida

Har kim menga yordam berishi mumkin?

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);
} 
0
Json_decode haqida nima ishlamaydi? (Ushbu kodda havola etilgan & nbsp; kodi yo'qligini hisobga olsak, men bu erda juda ko'p muammo bor)
qo'shib qo'ydi muallif Billy ONeal, manba
@MarkB: To'g'ri, lekin json_decode bu qat'iy deb o'ylamayman. ATMni sinovdan o'tkaza olmayman ...
qo'shib qo'ydi muallif Billy ONeal, manba
@Billy: Json_decode-ni foydalanganda, natijada zachiralarni bo'shim yo'q. Va bu katta muammo, chunki men bu qiymati olsam va buni Zend_Currency uchun beraman, bu qiymat raqamli emas. Va agar (float) qo'shsam ... 1 600 = 1 <= va bu juda katta muammo ^^
qo'shib qo'ydi muallif Raphaël, manba
@BillyONeal bilan bir xil, json_decode() ishlashi kerak. Qaysi xato xabari/natijasi bor?
qo'shib qo'ydi muallif Clement Herreman, manba
@Billy: Bu json emas. Kalitlar ko'rsatilmaydi.
qo'shib qo'ydi muallif Marc B, manba
qo'shib qo'ydi muallif user956584, manba

1 javoblar

Men Google valyutasini konvertyokilardan foydalanganda men ham ushbu muammo bilan shug'ullanardim. Ko'p narsalarni sinab ko'rdim va men uchun hech narsa qilinmadi. Nihoyat bu kodni topdim.

Quyidagilar bilan tanishishingiz mumkin:

$number = preg_replace('/[^a-z0-9.]/', '', $number);

yoki

$number = ereg_replace("[^A-Za-z0-9.]", "", $number );

Both wyokiks perfectly fine. ereg_replace() is depreciated function in php5.3.

1
qo'shib qo'ydi
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin