You can put the list of replacements in arrays:
<?php
/*
$list = [];
$list[] = "TALB20170826D-\$A$$-RA11.pdf";
$list[] = "TAP$20170826D-\$A$$-RA11.pdf";
$list[] = "TASD20170826D-\$A$$-RA11.pdf";
$list[] = "TAUA20170826D-\$A$$-RA11.pdf";
$list[] = "TAUB20170826D-\$A$$-RA11.pdf";
$list[] = "TAUC20170826D-\$A$$-RA11.pdf";
$list[] = "TAUD20170826D-\$A$$-RA11.pdf";
$list[] = "TBTP20170826D-\$A$$-RA11.pdf";
$list[] = "TCBY20170826D-\$A$$-RA11.pdf";
*/
$list = $html->find('a');
$abbr = [
"TALB",
"TAP",
// ...
];
$replacements = [
"ALBANY",
"Asia Pacific",
// ...
];
foreach ($list as &$el) {
$el->href = str_replace($abbr, $replacements, $el->href);
}
Demo
Or, to keep them all in one associative array (order doesn't matter and missing items just won't be replaced, no errors):
<?php
/*$list = [];
$list[] = "TALB20170826D-\$A$$-RA11.pdf";
$list[] = "TAP$20170826D-\$A$$-RA11.pdf";
$list[] = "TASD20170826D-\$A$$-RA11.pdf";
$list[] = "TAUA20170826D-\$A$$-RA11.pdf";
$list[] = "TAUB20170826D-\$A$$-RA11.pdf";
$list[] = "TAUC20170826D-\$A$$-RA11.pdf";
$list[] = "TAUD20170826D-\$A$$-RA11.pdf";
$list[] = "TBTP20170826D-\$A$$-RA11.pdf";
$list[] = "TCBY20170826D-\$A$$-RA11.pdf";*/
$list = $html->find('a');
$abbr = [
"TALB" => "ALBANY",
"TAP" => "Asia Pacific",
];
foreach ($list as &$el) {
$el->href = strtr($el->href, $abbr);
}
Demo
Or use array_map()
, maybe you'll find it a bit cleaner:
$list = array_map(function($el) use($abbr) {
return strtr($el, $abbr);
}, $list);