Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 MySQL SUBSTR()函数_Php_Mysql - Fatal编程技术网

Php MySQL SUBSTR()函数

Php MySQL SUBSTR()函数,php,mysql,Php,Mysql,我想比较$images,$uploads,但输出有不同的名称: $images = '/fiscalapplications/uploads/Image_00314_20200122.pdf'; $uploads = 'Image_00314_20200122.pdf'; 如何为$images to=Image_00314_20200122.pdf执行SUBSTR <?php //pulling images from mysql colum1 require_once 'datab

我想比较$images,$uploads,但输出有不同的名称:

$images = '/fiscalapplications/uploads/Image_00314_20200122.pdf';  
$uploads = 'Image_00314_20200122.pdf';
如何为$images to=Image_00314_20200122.pdf执行SUBSTR

<?php
//pulling images from mysql colum1
require_once 'database_connection.php';
$result = mysqli_query($conn,"SELECT check_pic_path FROM checklog");


$images = []; // store a list of images from the database

while ($row = mysqli_fetch_array($result)) {
    $images[] = $row['check_pic_path'] . "<br>";
}

//pulling pictures from specific path
$dir = "fiscalapplications/uploads";

$uploads = []; // store a list of files on disk

if(is_dir($dir)) {
    while (($file = readdir($dh)) !== false) {
        $uploads[] = $file . "<br>";
    }
}
}

//attempting to compare $image to $upload
$compare = array_diff($images, $uploads);
print_r($compare);
使用
basename()
从路径名中删除目录:

$images[] = basename($row['check_pic_path']) . "<br>";
$images[]=basename($row['check\u pic\u path'])。“
”;
使用
basename()
从路径名中删除目录:

$images[] = basename($row['check_pic_path']) . "<br>";
$images[]=basename($row['check\u pic\u path'])。“
”;
在MySQL中,它可能是

SUBSTRINT_INDEX(tablename.imagefield, '/', -1)
在MySQL中可能是这样

SUBSTRINT_INDEX(tablename.imagefield, '/', -1)
$uploadsnew=substr($images,strrpos($images,“/”)+1); strrpos获取斜杠最后一次出现的位置;substr返回该位置之后的所有内容

如果没有斜杠,这将无法正常工作,因为strrpos返回false。下面是一个更健壮的版本:

$pos=strrpos($url,“/”); $uploadsnew=$pos==false$url:substr($images,$pos+1)

$uploadsnew=substr($images,strrpos($images,“/”)+1); strrpos获取斜杠最后一次出现的位置;substr返回该位置之后的所有内容

如果没有斜杠,这将无法正常工作,因为strrpos返回false。下面是一个更健壮的版本:

$pos=strrpos($url,“/”); $uploadsnew=$pos==false$url:substr($images,$pos+1)

在PHP中:

$images = $images ?: '';
$uploads = substr($images, ($pos = strrpos($images, '/')) ? $pos : 0);
在MySQL中:

if( ifnull( locate( '/', check_pic_path ), 0 ) > 0, substring_index( check_pic_path, '/', -1 ), check_pic_path )
在PHP中:

$images = $images ?: '';
$uploads = substr($images, ($pos = strrpos($images, '/')) ? $pos : 0);
在MySQL中:

if( ifnull( locate( '/', check_pic_path ), 0 ) > 0, substring_index( check_pic_path, '/', -1 ), check_pic_path )

我不知道你在问什么。是否要检查图像文件名是否相同?我建议您不要将“
”放在数组本身中。养成总是把数据和表达分开的习惯。我不知道你在问什么。是否要检查图像文件名是否相同?我建议您不要将“
”放在数组本身中。养成总是将数据与表示分离的习惯。有时简单是最好的!;-)有时候简单是最好的!;-)