Snippet Information
Version: 16 (latest)
Author: alex
Language: php4
Licensed under GNU GPL v3
Other versions
"prop_search1" v.16 (latest)
Description
This snippet is insanely great.
Run
| View code [+] |
Create a snippet based on this »
<?php
$str = "Hi world. It's a beautiful/day. Hi?how are you,yeah!okay.";
echo $str;
echo "<br><br>";
$str = strtolower($str); // makes all characters lowercase
echo ($str)."<br><br>";
// ideally, would have code to replace all non-letters and apostrophe's with spaces.
$str = strip_tags($str);
$str = stripcslashes($str); // Unquotes a string quoted with addcslashes()
$str = stripslashes($str); // Unquotes a string quoted with addslashes()
$str = str_replace("/"," ",$str); // replace slashes with spaces
$str = str_replace("."," ",$str); // replace periods with spaces
$str = str_replace(","," ",$str);
$str = str_replace(";"," ",$str);
$str = str_replace(":"," ",$str);
$str = str_replace("!"," ",$str);
$str = str_replace("?"," ",$str);
$str = explode(" ",$str); // creates array of each word separated by space
print_r ($str);
echo "<br><br>";
$str2 = sort($str); // sorts words alphabetically
sort($str);
foreach ($str as $key => $val) { echo "str[" . $key . "] = " . $val . "\n";} // a way of printing words with array number = key and word itself = val
echo "<br><br>";
print_r ($str);
// add in counter for every duplicate word!
// up to this points, sorts
foreach ($str as $key => $val) { if ($val==$str[$key-1]) {$str[$key]="";}} // if this value of $str equals the last value of $str, then delete this value
echo "<br><br>";
print_r ($str);
$str2 = sort($str); // sorts words alphabetically
sort($str);
echo "<br><br>";
print_r ($str);
echo "<br><br>";
foreach ($str as $key => $val) { echo $val . " ";} // a way of printing all words remaining individually in $str array
?>

Comments (0) | View comments for all versions (0)
Log in if you have a Kogbox account.