Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 如何执行$filename=images/$filename2.jpg_Php - Fatal编程技术网

Php 如何执行$filename=images/$filename2.jpg

Php 如何执行$filename=images/$filename2.jpg,php,Php,我想做这样的事情,但我不知道如何: $file="4" $pic="../pics/$file.jpg"; $sound="../sounds/$file.mp3"; 我也会这样做 $nextpic="../pics/$file+1.jpg"; $next_file = $file + 1; $nextpic="../pics/$next_file.jpg"; 如果您的文件是一个数字,PHP会将其视为数字,而不管它是字符串还是什么。因此,您可以: $nextpic = "../pics/"

我想做这样的事情,但我不知道如何:

$file="4"
$pic="../pics/$file.jpg";
$sound="../sounds/$file.mp3";
我也会这样做

$nextpic="../pics/$file+1.jpg";
$next_file = $file + 1;
$nextpic="../pics/$next_file.jpg";

如果您的文件是一个数字,PHP会将其视为数字,而不管它是字符串还是什么。因此,您可以:

$nextpic = "../pics/".($file+1).".jpg";
另一方面,PHP的一个怪癖是如何处理包含数字的字符串。例如,如果您有一个文件“123lolz.jpg”,并将其递增,您将得到不需要的结果。愚蠢的东西

$file = "123lolz.jpg";
echo ($file+1)."\n"; // you get 124 and the rest of the file is discarded 

如果您的文件是一个数字,PHP会将其视为数字,而不管它是字符串还是什么。因此,您可以:

$nextpic = "../pics/".($file+1).".jpg";
另一方面,PHP的一个怪癖是如何处理包含数字的字符串。例如,如果您有一个文件“123lolz.jpg”,并将其递增,您将得到不需要的结果。愚蠢的东西

$file = "123lolz.jpg";
echo ($file+1)."\n"; // you get 124 and the rest of the file is discarded 

第一段代码很好

第二个应该是这样的:

$nextpic="../pics/" . ($file+1) . ".jpg";
还是像这样

$nextpic="../pics/$file+1.jpg";
$next_file = $file + 1;
$nextpic="../pics/$next_file.jpg";

第一段代码很好

第二个应该是这样的:

$nextpic="../pics/" . ($file+1) . ".jpg";
还是像这样

$nextpic="../pics/$file+1.jpg";
$next_file = $file + 1;
$nextpic="../pics/$next_file.jpg";
试试这个:

$nextpic="../pics/" . ($file+1) . ".jpg";
由于要添加某些内容,所以需要将其取出,因为使用运算符替换变量在字符串中不起作用

试试这个:

$nextpic="../pics/" . ($file+1) . ".jpg";

由于要添加某些内容,所以需要将其取出,因为使用运算符替换变量在字符串中不起作用

PHP.net提供了有关的完整文档。特别是在这些情况下:

$file="4"
$pic="../pics/$file.jpg";
$sound="../sounds/$file.mp3";
这将产生
$pic=“../pics/4.jpg”
$sound=“../sounds/4.mp3”

这将产生
$nextpic=“../pics/4+1.jpg”
。如果您想要5.jpg,请使用以下命令:

$nextpic="../pics/".($file+1).".jpg";

PHP.net提供了有关的完整文档。特别是在这些情况下:

$file="4"
$pic="../pics/$file.jpg";
$sound="../sounds/$file.mp3";
这将产生
$pic=“../pics/4.jpg”
$sound=“../sounds/4.mp3”

这将产生
$nextpic=“../pics/4+1.jpg”
。如果您想要5.jpg,请使用以下命令:

$nextpic="../pics/".($file+1).".jpg";

@谢谢你指出这一点。已编辑。@jprofitt感谢您指出这一点。编辑。