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. 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; 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; 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"; 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. 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 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! Link to comment https://forums.phpfreaks.com/topic/254864-replace-return-value/#findComment-1306819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.