If I understand You correctly, You've got a source_file.htm like the one below.
<!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>
Now, it is better to store the replacements for the alt tags of your images in an images.ini
file like that.
myprettypicture.jpg = "Here's a pretty picture"
mynotsoprettypicture.jpg = "Here's a not so pretty picture"
Now You can run this PHP script:
<?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"
?>
to get the 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>
Reference: str_replace, parse_ini_file, file_get_contents, file_put_contents