Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2016 13:26

Revisions

  1. @invalid-email-address Anonymous created this gist Sep 27, 2016.
    17 changes: 17 additions & 0 deletions debates.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?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);
    }