Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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 已弃用:函数split()已弃用。修复此特定实例_Php - Fatal编程技术网

Php 已弃用:函数split()已弃用。修复此特定实例

Php 已弃用:函数split()已弃用。修复此特定实例,php,Php,我正在尝试修复正在折旧的函数split的一个特定实例。以下是原文: list($file, $link, $text) = split("\|", $imagedb[$i]); 我试过了 list($file, $link, $text) = explode ("\|", $imagedb[$i]); 及 两者都不起作用,此脚本的作用是从文本文件中提取一行,如下所示: 21.jpg|http://www.kelleysisland.com/crafts/|Crafts Lakeview La

我正在尝试修复正在折旧的函数
split
的一个特定实例。以下是原文:

list($file, $link, $text) = split("\|", $imagedb[$i]);
我试过了

list($file, $link, $text) = explode ("\|", $imagedb[$i]);

两者都不起作用,此脚本的作用是从文本文件中提取一行,如下所示:

21.jpg|http://www.kelleysisland.com/crafts/|Crafts Lakeview Lane
并创建一个链接的随机照片网格,并在下面显示链接标题:

http://kelleysisland.com/where-to-stay/cottages-and-homes
以下是完整的脚本(如果有帮助):

$sFilename = "imagedb2.txt";
$sTemplate = "template.html";
$thumburl = "http://www.kelleysisland.com/thumbs";
function show_thumbs() {
    global $sFilename, $sTemplate, $thumburl;
    $imagedb=file($sFilename);
    shuffle($imagedb);
    $i=0;
    while($i<count($imagedb)) {
        $d=1;
        $template=file_get_contents($sTemplate);
        while(preg_match_all("/<% image$d %>/", $template, $matches)) {
            list($file, $link, $text) = split("\|", $imagedb[$i]);
            $template=preg_replace("/<% image$d %>/", "<a href=\"$link\" target=\"_blank\"><img src=\"$thumburl/$file\" border=0></a>", $template);
            $template=preg_replace("/<% text$d %>/", "<a href=\"$link\" target=\"_blank\">$text</a>", $template);
            $d++;
            $i++;
        }
        echo $template;
    }
}
$sFilename=“imagedb2.txt”;
$sTemplate=“template.html”;
$thumburl=”http://www.kelleysisland.com/thumbs";
函数show_thumbs(){
全局$sFilename、$sTemplate、$thumburl;
$imagedb=文件($sFilename);
洗牌($imagedb);
$i=0;

虽然($i)你不需要在
explode
split
函数中转义
字符。
explode(“|“,$imagedb[$i]);
就足够了。但是在
preg\u split中你有escape
preg\u split(/\\124;/”,$imagedb[$i])
谢谢!这就解决了!!只需使用:
explode(“),$imagedb[$i]);
$sFilename = "imagedb2.txt";
$sTemplate = "template.html";
$thumburl = "http://www.kelleysisland.com/thumbs";
function show_thumbs() {
    global $sFilename, $sTemplate, $thumburl;
    $imagedb=file($sFilename);
    shuffle($imagedb);
    $i=0;
    while($i<count($imagedb)) {
        $d=1;
        $template=file_get_contents($sTemplate);
        while(preg_match_all("/<% image$d %>/", $template, $matches)) {
            list($file, $link, $text) = split("\|", $imagedb[$i]);
            $template=preg_replace("/<% image$d %>/", "<a href=\"$link\" target=\"_blank\"><img src=\"$thumburl/$file\" border=0></a>", $template);
            $template=preg_replace("/<% text$d %>/", "<a href=\"$link\" target=\"_blank\">$text</a>", $template);
            $d++;
            $i++;
        }
        echo $template;
    }
}