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;
}
}