Esempio n. 1
0
    }
    // Ensures the last word ends with punctuation, naturally.
    $temp_words = preg_split('#\\s+#', $out_string, null, PREG_SPLIT_NO_EMPTY);
    while (substr($temp_words[count($temp_words) - 1], -1, 1) != "." && substr($temp_words[count($temp_words) - 1], -1, 1) != "!" && substr($temp_words[count($temp_words) - 1], -1, 1) != "?") {
        $temp_key = $temp_words[count($temp_words) - 2] . " " . $temp_words[count($temp_words) - 1];
        $out_string .= " ";
        $out_string .= $triples_database[$temp_key][rand(0, count($triples_database[$temp_key]))];
        $temp_words = preg_split('#\\s+#', $out_string, null, PREG_SPLIT_NO_EMPTY);
    }
    echo caps($out_string);
}
function caps($in_string)
{
    $words = preg_split('#\\s+#', $in_string, null, PREG_SPLIT_NO_EMPTY);
    $words[0] = ucFirst($words[0]);
    for ($i = 1; $i < count($words); $i++) {
        // If the previous word's last character is "!, ., or ?", capitalize this word
        if (substr($words[$i - 1], -1, 1) == "." || substr($words[$i - 1], -1, 1) == "!" || substr($words[$i - 1], -1, 1) == "?") {
            $words[$i] = ucFirst($words[$i]);
        }
    }
    $out_string = "";
    foreach ($words as $word) {
        $out_string .= $word;
        $out_string .= " ";
    }
    return $out_string;
}
if ($_POST["functionname"] == "makeBlurb") {
    echo makeBlurb();
}
Esempio n. 2
0
        $out_string .= $triples_database[$temp_key][rand(0, count($triples_database[$temp_key]))];
        $temp_words = preg_split('#\\s+#', $out_string, null, PREG_SPLIT_NO_EMPTY);
    }
    echo caps($out_string);
}
function caps($in_string)
{
    $words = preg_split('#\\s+#', $in_string, null, PREG_SPLIT_NO_EMPTY);
    $words[0] = ucFirst($words[0]);
    for ($i = 1; $i < count($words); $i++) {
        // If the previous word's last character is "!, ., or ?", capitalize this word
        if (substr($words[$i - 1], -1, 1) == "." || substr($words[$i - 1], -1, 1) == "!" || substr($words[$i - 1], -1, 1) == "?") {
            $words[$i] = ucFirst($words[$i]);
        }
    }
    $out_string = "";
    foreach ($words as $word) {
        $out_string .= $word;
        $out_string .= " ";
    }
    return $out_string;
}
makeBlurb($triples_database);
?>


</body>
</html>