简体   繁体   English

$ exif问题中的PHP语法

[英]PHP syntax in $exif issue

Hello would like to know how can I get this syntax correct. 您好想知道如何正确使用此语法。

I got this code from: http://php.net/manual/en/function.exif-read-data.php 我从以下网址获得了此代码: http : //php.net/manual/en/function.exif-read-data.php

code below: 下面的代码:

<?php

$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>

now I want to add a line which actualy gives you the image name. 现在,我想添加一条实际上为您提供图像名称的行。 test1.jpg etcs from php array. 来自php数组的test1.jpg等。

test/<?=$prod['image_url'] ?>

like this 像这样

<?php

$exif = exif_read_data('test/<?=$prod['image_url'] ?>', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>

replacing 更换

tests/test2.jpg

with

test/<?=$prod['image_url'] ?>

but the syntax is incorrect. 但是语法不正确。 Please suggest how it can be corrected. 请提出如何纠正它。

modify 修改

exif_read_data('test/<?=$prod['image_url'] ?>', 0, true);

to

exif_read_data('test/' . $prod['image_url'], 0, true);

Full code 完整代码

$exif = exif_read_data('test/' . $prod['image_url'], 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>

Error reason : You can't put php tag inside another php tag 错误原因:您不能将php标记放在另一个php标记内

ouch. 哎哟。 ok, try this. 好的,试试这个。 It allows you to use the $prod['image_url'] in the string $filename and then pass $filename to the exif_read_data function. 它允许您在字符串$ filename中使用$ prod ['image_url'],然后将$ filename传递给exif_read_data函数。

<?php

$filename = sprintf("tests/%s",$prod['image_url']);

$exif = exif_read_data($filename, 0, true);

printf("%s<br/>",$filename);

foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM