小编Ver*_*era的帖子

PHP如何使用curl打开几个源?

我有一些代码来获取site1的json内容,但我还需要获取site2的内容.我应该为site2重新编写所有这些行吗?或者我可以添加一个以上的URL curl_setopt

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,"http://site1.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$outputJson = curl_exec($ch);
if ($outputJson === FALSE) {
    echo 'Sorry, This service is currently unavailable: '. curl_error($ch);
}
Run Code Online (Sandbox Code Playgroud)

php api url curl

3
推荐指数
1
解决办法
123
查看次数

如何使用"tail"将字符串转换为float?


我将字符串转换为float有问题.

print gettype($value[$id]); //returns string

var_dump($value[$id]);//returns string '34,7140' (length=7)

$float = floatval($value[$id]); 

print gettype($float);//returns double

var_dump($float);//returns float 34

echo $float;//returns 34
Run Code Online (Sandbox Code Playgroud)

我不明白为什么"34"?为什么$ float不是'34,7140'?
我如何得到$ float = 34,7140?

php string floating-point integer decimal

2
推荐指数
1
解决办法
4615
查看次数

PHP如何从R + G + B数组中获取HEX颜色代码?


我有一个数组:

Array
(
    [red] => 252
    [green] => 168
    [blue] => 166
    [alpha] => 0
)
Run Code Online (Sandbox Code Playgroud)

它是函数imagecolorsforindex的输出.
如何从这些元素中获取HTML代码?例如:#99CCFF

html php rgb hex

2
推荐指数
1
解决办法
1169
查看次数

如何通过它的键对数组进行排序/排序?


该数组没有[0]和[2]键.

Array
(
[1] => 5.2836

[3] => 2.5749

[4] => 134.19

[5] => 5.8773

[6] => 1.3504
....
Run Code Online (Sandbox Code Playgroud)

如何将其更改为:

Array
(
[0] => 5.2836

[1] => 2.5749

[2] => 134.19

[3] => 5.8773

[4] => 1.3504
....
Run Code Online (Sandbox Code Playgroud)

在php中有这样一个任务的内置函数吗?

php arrays sorting key

0
推荐指数
1
解决办法
101
查看次数

标签 统计

php ×4

api ×1

arrays ×1

curl ×1

decimal ×1

floating-point ×1

hex ×1

html ×1

integer ×1

key ×1

rgb ×1

sorting ×1

string ×1

url ×1