Created
March 27, 2015 05:04
-
-
Save a904guy/671e922a8ff77f32ae8f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Created by [BombSquad Inc](http://www.bmbsqd.com) | |
* User: Andy Hawkins | |
* Date: 3/26/15 | |
* Time: 9:01 PM | |
*/ | |
if (php_sapi_name() == "cli") { | |
//Launch Web Server | |
print "Open browser to: http://localhost:7867 \n"; | |
passthru('php -S localhost:7867 tellmeastory.php'); | |
} | |
?> | |
<form action="?" method="post"> | |
<input type="text" name="find" placeholder="Sentence to find" style="width:500px;" value="<?php echo $_POST['find'] ?>"><br/> | |
<input type="number" name="width" placeholder="Min words in line" style="width:500px;" value="<?php echo $_POST['width'] ?>" /><br/> | |
<input type="number" name="gerth" placeholder="Max Words in line" style="width:500px;" value="<?php echo $_POST['gerth'] ?>" /><br/> | |
<textarea name="story" placeholder="Large body of text" style="width:500px; height:500px"><?php echo $_POST['story'] ?></textarea><br/> | |
<button type="submit">Submit</button> | |
</form> | |
<pre><?php if(count($_POST) > 0) tellmeastory();?></pre> | |
<?php | |
function tellmeastory() | |
{ | |
$match = str_split(preg_replace('/[^\da-z]/i','',$_POST['find'])); | |
$search = preg_split("/\s+/", preg_replace('/[^\da-z ]/i',' ',$_POST['story'])); | |
$toSkip = $_POST['width']; | |
$maxSkip = $_POST['gerth']; | |
// var_dump($match); | |
// var_dump($search); | |
$n = 0; | |
$story = []; | |
while(count($match) != $n) | |
{ | |
$find = strtolower($match[$n]); | |
$skipN = 0; | |
foreach($search as $k => $v) | |
{ | |
$first = strtolower($v[0]); | |
if($find == $first && ( $skipN > $toSkip || count($story) == 0 ) ) | |
{ | |
$story[] = "\n"; | |
$story[] = $v; | |
unset($search[$k]); | |
break 1; | |
} | |
// if($skipN > $maxSkip && strpos($v, $find) !== FALSE && count($story)>0 && strlen($v) > 5) | |
// { | |
// list($before, $after) = explode($find, $v, 2); | |
// $story[] = $before.'-'; | |
// $story[] = "\n"; | |
// $story[] = $find.$after; | |
// unset($search[$k]); | |
// break 1; | |
// } | |
if(count($story)>0) | |
$story[] = $v; | |
unset($search[$k]); | |
$skipN++; | |
} | |
//unset($match[$n]); | |
$n++; | |
} | |
echo implode(' ',array_merge($story,$search)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment