Skip to content

Instantly share code, notes, and snippets.

@setola
Created July 14, 2017 15:22
Show Gist options
  • Save setola/2ce4ed4d196001af60e2c153d4d6770d to your computer and use it in GitHub Desktop.
Save setola/2ce4ed4d196001af60e2c153d4d6770d to your computer and use it in GitHub Desktop.
CSV to RewriteRule
<?php
$inHandler = fopen("in.csv", "r");
$outHandler = fopen("out.txt", "w");
$row = 0;
while (($data = fgetcsv($inHandler, 1000, ",")) !== FALSE) {
$row++;
if (1 == $row) continue;
$data = array_map(function ($item) {
return str_replace('http://gsped.com', '', $item);
}, $data);
fwrite($outHandler, vsprintf('RewriteRule "^%s$" "%s" [R=%s,L]' . PHP_EOL, $data));
}
fclose($inHandler);
fclose($outHandler);
printf("wrote %s lines" . PHP_EOL, $row);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment