大佬教程收集整理的这篇文章主要介绍了php-来自Value API的HTML星级,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
自从我使用HTML和@L_450_1@以来,已经有很长时间了.
通过第三方客户反馈工具,他们提供了API.很容易从API中提取“幸福值”,并以百分比显示.没事,没事..
<?PHP include('https://app.customerthermometer.com/api.PHP?apiKey=********************&getmethod=getHappinessvalue'); ?>
我想知道并尝试使用文档中的PHP Includes来实现这一点,并使视图更加丰富多彩.例如;
http://jsfiddle.net/b6tqtaLn/1/
@L_197_9@
将百分比(例如,API的95%)转换为可以在星标中看到的值的最佳方法是什么?
提前致谢!
解决方法:
首先,您需要定义要使用的(最大)星数.
例如,如果您从API获得的最大值是100%,并且您使用的是10星,那么这样做非常容易.
$api_percentage_value = '95%'; // Given from API
$converted_percentage_value = (int) $api_percentage_value; // Make it an Integer
echo $converted_percentage_value; // outcome = 95 (Integer)
/**
* Personally I would like to have the 'raw' data to be in a String like above.
* But if you prefer to have it in a single String simply delete the `$api_percentage_value` and drop the API data inside `$converted_percentage_value` right away.
* But remember you need to add `(int)` before the result. Otherwise it will not be an Integer.
* Also, incase they do deliver only an Integer, it might work for some time.
* But we all kNow many API developers just change stuff within their output without communication (before and/or after the changE).
* So I prefer to have it split up and make my own validation.
*/
所以,现在我们有@L_674_13@整数.
假设1星= 10分.
其背后的计算将是:
95 / 100 = 0,95. * 10. = 9.5 (stars) // Incase 1 star = 20 points: simply do 95 / 200, etc.
-要么-
$stars = ($converted_percentage_value / 100) * 10;
echo $stars; // outcome: (int) 9.5
$score = floor($converted_percentage_value); // outcome: 9.
现在您可以进行一次foreach,并且每次都减去$score($score–).一旦$score位于(int)1以下,就可以停止脚本.
您对如何执行此操作有想法吗?
还是您希望有@L_674_13@示例代码,用于在带倒计时的foreach中显示星星?
以上是大佬教程为你收集整理的php-来自Value API的HTML星级全部内容,希望文章能够帮你解决php-来自Value API的HTML星级所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。