Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-变量问题_Php_Variables - Fatal编程技术网

PHP-变量问题

PHP-变量问题,php,variables,Php,Variables,不确定这个问题是否有更好的标题,但基本上我的代码如下: <?php $v = file_get_contents('http://examplecom/index.php?='); $popularnames = array('Gravity Falls','The Amazing World of Gumball','South Park','American Dad'); ?> 使用此选项效果良好,因此变量包含的内容没有问题: <?php $v = file_get

不确定这个问题是否有更好的标题,但基本上我的代码如下:

<?php

$v = file_get_contents('http://examplecom/index.php?=');

$popularnames = array('Gravity Falls','The Amazing World of Gumball','South Park','American Dad');

?>
使用此选项效果良好,因此变量包含的内容没有问题:

<?php $v = file_get_contents('http://example.com/index.php?q='.urlencode($popularnames[0])); echo $v; ?>

有什么想法吗

从下面的答案可以看出,我怎样才能使它更紧凑,从而更好地使我能够只做


请注意,回显的$v2将在
src=”“

但我的结果应该让我明白

然后将URL片段存储在
$v
中:

$v = 'http://examplecom/index.php?=';
$v = file_get_contents('http://examplecom/index.php?=');
当前,您正在获取该URL片段的文件内容,并将其存储在
$v
中:

$v = 'http://examplecom/index.php?=';
$v = file_get_contents('http://examplecom/index.php?=');
如果该不完整URL的内容为空,则
$v
自然为空。将一个空字符串与另一个字符串连接将只产生另一个字符串


(旁注:我不确定您打算在
index.php
上做什么,因为您发送的查询字符串值没有与之关联的键。可能您忘记了在URL片段中包含键?

完美,但有没有办法使其更整洁和紧凑:Edited mainpost@Kyubeh2435436:定义“更整洁、更紧凑”. 将字符串值设置为变量是非常简单和“紧凑”的。就像我如何让它能够执行和e.t.c任何我想让它执行的文件内容一样。@Kyubeh2435436:不能将函数调用别名为变量名。您必须实际调用该函数。您可以将函数调用的结果存储在变量中。但是,
$v2.$something
不能直接代替
函数($something)
。这是我能得到的最紧凑的功能。
$v = file_get_contents('http://examplecom/index.php?=');