cat250 Posted January 12, 2012 Share Posted January 12, 2012 Hello again. I use echo "Rating:".$json['Rating]."/10"; and get in return: 7.5/10 - it's ok. But I want to replace 7.5 with 75.png (image), 6.3 with 63.png, 9.4 with 94.png... hope u understand. Know someone how I can do this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/ Share on other sites More sharing options...
QuickOldCar Posted January 12, 2012 Share Posted January 12, 2012 Here's a simple example <?php $rating = "7.5/10"; $rating_number = explode("/",$rating); $rating_number[0] = str_replace(".","",$rating_number[0]); $image_number = $rating_number[0].".png"; echo $image_number; ?> But in your case you already have value can use. $image_number = $json['Rating]; $image_number = str_replace(".","",$image_number).".png"; echo $image_number; Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306805 Share on other sites More sharing options...
QuickOldCar Posted January 12, 2012 Share Posted January 12, 2012 Missed a single quote $image_number = $json['Rating']; $image_number = str_replace(".","",$image_number).".png"; echo $image_number; Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306809 Share on other sites More sharing options...
QuickOldCar Posted January 12, 2012 Share Posted January 12, 2012 Might as well do this all one line, the missing quote was messing me up before. $image_number = str_replace(".","",$json['Rating']).".png"; Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306811 Share on other sites More sharing options...
cat250 Posted January 12, 2012 Author Share Posted January 12, 2012 Thank u so much, this is perfect. But... i was a big idiot in first post... i want only "first number" and now don't know how to do this. Can u help me, again, please? Thanks thanks. It's ok anyway. Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306814 Share on other sites More sharing options...
QuickOldCar Posted January 12, 2012 Share Posted January 12, 2012 You mean something like this? $image_number = floor($json['Rating']).".png"; So if the json value was 7.5, it would become 7.png Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306818 Share on other sites More sharing options...
cat250 Posted January 12, 2012 Author Share Posted January 12, 2012 Can't belive, it's perfect. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.