I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because they're applied differently but in some cases they are applied the same. In these cases, rather than write out a separate foreach
for each one, this is what I'm trying to simplify:
<?php
public function generateRobotsFile($rbfile, $smfile) {
$tab = array();
$tab['SemBot'] = array('Googlebot',"bingbot\nCrawl-delay: 5",'MSNBot');
$tab['Lang'] = array('eb');
$tab['Files'] = array('address.php','cart.php');
$tab['Folder'] = array('classes','docs','themes');
fwrite($writeFd, "\nUser-agent: *\n");
foreach ($tab['Lang'] as $Lang) {
fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Lang . "\n");
}
foreach ($tab['Folder'] as $Folder) {
fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Folder . "\n");
}
foreach ($tab['SemBot'] as $SemBot) {
fwrite($writeFd, "User-agent: ' . $SemBot . "\n");
foreach ($tab['Files'] as $Files) {
fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Files . "\n");
}
foreach ($tab['Folder'] as $Folder) {
fwrite($writeFd, 'Disallow: ' . __PS_BASE_)URI__ . $Folder . "/\n");
}
}
The arrays must remain separated but in some cases they are looped through the same disallow rule so I'm reaching for a foreach
array in array but haven't quite grasped it yet.
"User-agent: '
uses the wrong quote types and a bracket in__PS_BASE_)URI__
– MrLore May 26 at 3:01