Created
July 14, 2017 15:22
-
-
Save setola/2ce4ed4d196001af60e2c153d4d6770d to your computer and use it in GitHub Desktop.
CSV to RewriteRule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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