php检索文本文件中的图像ALT标记
我正试图建立一个小画廊的基础上 目前,此图库使用图像文件名提供alt标记。我需要一种方法来使用与我的图像相关联的文本文件,如下所示:php检索文本文件中的图像ALT标记,php,image,tags,alt,Php,Image,Tags,Alt,我正试图建立一个小画廊的基础上 目前,此图库使用图像文件名提供alt标记。我需要一种方法来使用与我的图像相关联的文本文件,如下所示: myprettypicture.jpg = "Here's a pretty picture" mynotsoprettypicture.jpg = "Here's a not so pretty picture" 然后用php gallery检索它,将其作为ALT标记。到目前为止,我已经查看了几个图库,有几个使用
myprettypicture.jpg = "Here's a pretty picture"
mynotsoprettypicture.jpg = "Here's a not so pretty picture"
然后用php gallery检索它,将其作为ALT标记。到目前为止,我已经查看了几个图库,有几个使用这种方法,但我不知道如何在我的实际图库中使用它…你知道一个脚本或一个简单的方法接近我正在寻找的吗
谢谢大家! 如果我没弄错的话,您已经有了一个类似下面的source_file.htm
<!DOCTYPE html>
<html>
<body>
<img src="myprettypicture.jpg" alt="myprettypicture.jpg" height="50" width="50">
<img src="mynotsoprettypicture.jpg" alt="mynotsoprettypicture.jpg" height="50" width="50">
</body>
</html>
现在可以运行以下PHP脚本:
<?php
$ini_array = parse_ini_file("images.ini"); // load "images.ini" into array
foreach($ini_array as $key => $val)
{
$img[] = 'alt="' . $key . '"';
$alt[] = 'alt="' . $val . '"';
}
$source = file_get_contents('source_file.htm'); // get Your "source_file.htm"
$target = str_replace($img, $alt, $source); // make all required replacements
file_put_contents('target_file.htm', $target); // save the result to "target_file.htm"
?>
参考:
,这正是我要搜索的:某种图像文件夹的.ini包装。非常感谢你的评论,非常有用。
<?php
$ini_array = parse_ini_file("images.ini"); // load "images.ini" into array
foreach($ini_array as $key => $val)
{
$img[] = 'alt="' . $key . '"';
$alt[] = 'alt="' . $val . '"';
}
$source = file_get_contents('source_file.htm'); // get Your "source_file.htm"
$target = str_replace($img, $alt, $source); // make all required replacements
file_put_contents('target_file.htm', $target); // save the result to "target_file.htm"
?>
<!DOCTYPE html>
<html>
<body>
<img src="myprettypicture.jpg" alt="Here's a pretty picture" height="50" width="50">
<img src="mynotsoprettypicture.jpg" alt="Here's a not so pretty picture" height="50" width="50">
</body>
</html>