Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2016 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/ddefcadcd2e8e6e604f95c7fea318868 to your computer and use it in GitHub Desktop.
Save anonymous/ddefcadcd2e8e6e604f95c7fea318868 to your computer and use it in GitHub Desktop.
<?php
$dirname = dirname(__FILE__);
$filename = "debates.txt"; #assumes you have https://gist.github.com/anonymous/5d7f8d11e297e5b5549a520d1471dc46
$speaker = ""; $speeches = array();
foreach(file("$dirname/$filename") as $line) {
$withoutname = preg_replace("/^(HOLT|CLINTON|TRUMP):/","", $line);
if ($line!=$withoutname) {
$speaker = substr($line, 0, strpos($line, ":"));
}
if (trim($withoutname) && trim($withoutname)!="(APPLAUSE)") {
$speeches[$speaker] .= $withoutname;
}
}
foreach($speeches as $speaker => $speech) {
file_put_contents("$dirname/$speaker.txt", $speech);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment