2014-02-17 3 views
2

에 의해 검색 할 수 있습니다. 나는이 같은 텍스트 내 이미지와 관련된 파일, 뭔가를 사용하는 방법이 필요합니다 :이미지 ALT 태그는이 갤러리는 이미지 파일 이름을 사용하여 ALT 태그를 제공, 내가 지금은 <a href="http://davidwalsh.name/generate-photo-gallery" rel="nofollow">david walsh's howto.</a></p> <p>에 따라 설치에 약간의 갤러리를 시도하고 PHP

myprettypicture.jpg = "Here's a pretty picture" 
mynotsoprettypicture.jpg = "Here's a not so pretty picture" 

은 그 다음의 PHP 갤러리와 ALT로 태그를 넣어이를 검색 할 수 있습니다. 지금까지 여러 갤러리를 살펴 보았지만이 방법을 사용하는 몇 가지 방법이 있지만 실제 갤러리와 함께 사용하는 방법을 모릅니다 ...
내가 사용하는 스크립트 나 간단한 방법을 알고 있습니까? 내가 찾고있어?

고맙습니다!

답변

1

본인을 올바르게 이해하면 아래와 같은 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> 

지금, 그 같은 images.ini 파일에 이미지의 ALT 태그에 대한 교체를 저장하는 것이 좋습니다.

<?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" 
?> 

가 얻을 수있는 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> 

참조 :

myprettypicture.jpg = "Here's a pretty picture" 
mynotsoprettypicture.jpg = "Here's a not so pretty picture" 

지금이 PHP 스크립트를 실행할 수 있습니다 str_replace, 정확히 무엇을의 parse_ini_file, file_get_contents, file_put_contents

+0

I 검색되었습니다 hing : 이미지 폴더를위한 일종의 .ini 래퍼. 당신이 가진 코멘트에 대해 많은 도움을 주셔서 감사합니다. – mediaklan