Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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/3/arrays/13.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/4/video/2.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 从EXIF数据中提取描述并排除重复文本_Php_Arrays_Exif_Array Unique - Fatal编程技术网

Php 从EXIF数据中提取描述并排除重复文本

Php 从EXIF数据中提取描述并排除重复文本,php,arrays,exif,array-unique,Php,Arrays,Exif,Array Unique,我正在制作一个肖像图片库,从Exif数据中提取文本。当我编辑这些图片时,我会写下这些人的名字,然后在我的图片库中显示为标题 我想制作一个列表,但不知道如何将其制作成一个数组,通过array\u unique()可以从中排除重复项 我的代码是: $imgdir = 'images/'; //pick your folder ie.: 'images/' $current_folder = basename(dirname(__FILE__)); $allowed_types = array('pn

我正在制作一个肖像图片库,从Exif数据中提取文本。当我编辑这些图片时,我会写下这些人的名字,然后在我的图片库中显示为标题

我想制作一个列表,但不知道如何将其制作成一个数组,通过
array\u unique()
可以从中排除重复项

我的代码是:

$imgdir = 'images/'; //pick your folder ie.: 'images/'
$current_folder = basename(dirname(__FILE__));
$allowed_types = array('png','jpg','jpeg','gif');

$dimg = opendir($imgdir);
while($imgfile = readdir($dimg)){
    if(in_array(strtolower(substr($imgfile,-3)),$allowed_types)){
        $a_img[] = $imgfile;
        sort($a_img);
        reset ($a_img);
    }
}
$totimg = count($a_img);

?><!DOCTYPE html>
<html>
<head>
    <title>Names listing</title>
</head>
<body>
<?php
for ($x=0; $x < $totimg; $x++){
    if ($x == ($totimg-1))
        $_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).'';
    else
        $_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).', ';
    $_unique = $_content;
    echo $_unique;
}    
?>
</body>
</html>
我想要的是:

John, Jane, ... etc.

提前感谢。

您应该将所有
ImageDescription
值存储在临时数组中(例如
$descriptions
),然后在循环完成对临时数组的调用
array\u unique()
以删除重复项后,您可以选择按字母顺序排列值,最后,使用“
内爆()
”将剩余的值转换为字符串,并用[逗号和空格]分隔这些值

for($x=0; $x<$totimg; ++$x){
    $descriptions[]=exif_read_data('images/'.$a_img[$x])[ImageDescription];
}
$descriptions=array_unique($descriptions);       // remove duplicates before sorting
sort($descriptions);                             // sort alphabetically
echo implode(', ',$descriptions);                // display csv

用于($x=0;$xI必须添加一些括号,但非常感谢!@kdt2017是的,很抱歉我太草率了。我现在已经修复了我的代码。你不应该在你的
exif
调用周围添加额外的括号。如果我错了,请告诉我。它很好,谢谢。我也尝试过对列表排序,但没有运气。有简单的方法吗你为什么这么做?
for($x=0; $x<$totimg; ++$x){
    $descriptions[]=exif_read_data('images/'.$a_img[$x])[ImageDescription];
}
$descriptions=array_unique($descriptions);       // remove duplicates before sorting
sort($descriptions);                             // sort alphabetically
echo implode(', ',$descriptions);                // display csv