• 1 رای - 5 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
بیرون کشیدن یک متغییر با استفاده از php
#1
سلام
من می خوام از توی متن زیر یه سری از اعداد که مربوط به یه بخش خاص هستن رو از توی متن زیر بیرون بکشم
فرض کنید عدد 14,815,000 مد نظر باشه(سرچ کنید که راحتتر پیداش کند که این عدد مربوط به)
current>>ati2>>h
((.میشه
البته اعداد مرتب عوض میشن به همین خاطر می خوام تابعم هوشمند باشه: ممنون میشم اگه کمکم کنید
کد پی‌اچ‌پی:
{"current":{"ati1":{"p":"14,310,000","h":"14,365,000","l":"14,300,000","d":"100,000","dp":"0.7","dt":"low","t":"۱۴:۵۵","t-g":"۱۴:۵۵","settlement":"14,406,875"},"ati2":{"p":"14,690,000","h":"14,790,000","l":"14,665,000","d":"120,000","dp":"0.82","dt":"low","t":"۱۵:۰۰","t-g":"۱۵:۰۰","settlement":"14,822,558"},"ati3":{"p":"15,160,000","h":"15,285,000","l":"15,160,000","d":"145,000","dp":"0.96","dt":"low","t":"۱۴:۴۰","t-g":"۱۴:۴۰","settlement":"15,317,067"},"ati4":{"p":"15,750,000","h":"15,865,000","l":"15,720,000","d":"130,000","dp":"0.83","dt":"low","t":"۱۴:۵۶","t-g":"۱۴:۵۶","settlement":"15,894,539"},"ati5":{"p":"16,345,000","h":"16,465,000","l":"16,320,000","d":"125,000","dp":"0.76","dt":"low","t":"۱۵:۰۰","t-g":"۱۵:۰۰","settlement":"16,485,086"},"ati1_checkout":{"p":"14,406,875","h":"14,406,875","l":"14,406,875","d":"6,923","dp":"0.05","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati2_checkout":{"p":"14,822,558","h":"14,822,558","l":"14,822,558","d":"37,836","dp":"0.26","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati3_checkout":{"p":"15,317,067","h":"15,317,067","l":"15,317,067","d":"26,602","dp":"0.17","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati4_checkout":{"p":"15,894,539","h":"15,894,539","l":"15,894,539","d":"45,937","dp":"0.29","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati5_checkout":{"p":"16,485,086","h":"16,485,086","l":"16,485,086","d":"62,145","dp":"0.38","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"}}} 
  پاسخ
تشکر شده توسط :
#2
هیچ کس نیست که جواب بده!!
  پاسخ
تشکر شده توسط :
#3
http://php.net/manual/en/function.strpos.php
https://www.w3schools.com/PhP/func_string_explode.asp
http://php.net/manual/en/function.preg-match-all.php
وبلاگ rezaonline.net/blog
سفارش برنامه نویسی reza.biz
Php , mysql , postgresql , redis , Yii and ... Cool
  پاسخ
تشکر شده توسط : ayoubsys
#4
ممنون از این که جواب میدی دوست عزیز
من می خوام از این دستور استفاده کنم:اول داده های بالا رو برابر با متغییر $dddd قرار بدم بعد یه متغییر دیگه به اسم $data بسازم به صورت زیر که اطلاعات رو از توی اون بتونم انتخاب کنم ولی نمیدونم چرا جواب نمیده!لطفا کمکم کنید ممنون.
کد پی‌اچ‌پی:
$data=json_encode($dddd,true);
echo 
$data;
$GGGG[]=$data['current']['ati1']['h']; 
  پاسخ
تشکر شده توسط :
#5
print_r کنید نتیجه رو ببینید چجوری در میاد
وبلاگ rezaonline.net/blog
سفارش برنامه نویسی reza.biz
Php , mysql , postgresql , redis , Yii and ... Cool
  پاسخ
تشکر شده توسط :
#6
print_r()
که می کنم بازهم همون رو بهم بر می گردونه!!!
کد پی‌اچ‌پی:
Array ( [0] =>{ ......همون مقدار قبل....}) 
  پاسخ
تشکر شده توسط :
#7
کد پی‌اچ‌پی:
<?php
$json 
json_decode('{"current":{"ati1":{"p":"14,310,000","h":"14,365,000","l":"14,300,000","d":"100,000","dp":"0.7","dt":"low","t":"۱۴:۵۵","t-g":"۱۴:۵۵","settlement":"14,406,875"},"ati2":{"p":"14,690,000","h":"14,790,000","l":"14,665,000","d":"120,000","dp":"0.82","dt":"low","t":"۱۵:۰۰","t-g":"۱۵:۰۰","settlement":"14,822,558"},"ati3":{"p":"15,160,000","h":"15,285,000","l":"15,160,000","d":"145,000","dp":"0.96","dt":"low","t":"۱۴:۴۰","t-g":"۱۴:۴۰","settlement":"15,317,067"},"ati4":{"p":"15,750,000","h":"15,865,000","l":"15,720,000","d":"130,000","dp":"0.83","dt":"low","t":"۱۴:۵۶","t-g":"۱۴:۵۶","settlement":"15,894,539"},"ati5":{"p":"16,345,000","h":"16,465,000","l":"16,320,000","d":"125,000","dp":"0.76","dt":"low","t":"۱۵:۰۰","t-g":"۱۵:۰۰","settlement":"16,485,086"},"ati1_checkout":{"p":"14,406,875","h":"14,406,875","l":"14,406,875","d":"6,923","dp":"0.05","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati2_checkout":{"p":"14,822,558","h":"14,822,558","l":"14,822,558","d":"37,836","dp":"0.26","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati3_checkout":{"p":"15,317,067","h":"15,317,067","l":"15,317,067","d":"26,602","dp":"0.17","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati4_checkout":{"p":"15,894,539","h":"15,894,539","l":"15,894,539","d":"45,937","dp":"0.29","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"},"ati5_checkout":{"p":"16,485,086","h":"16,485,086","l":"16,485,086","d":"62,145","dp":"0.38","dt":"high","t":"۸:۳۱","t-g":"۸:۳۱"}}} ',true);
//print_r($json);
echo $json['current']['ati1']['h'];
echo 
"<hr>";
echo 
$json['current']['ati2']['h']; 
وبلاگ rezaonline.net/blog
سفارش برنامه نویسی reza.biz
Php , mysql , postgresql , redis , Yii and ... Cool
  پاسخ
تشکر شده توسط : iran2018 soheyl_ir89 ayoubsys
#8
ممنونم. درست شد
HeartHeartHeartHeart
لطف کردی دوست عزیز
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان