<?php
//string string of invalid chars and make it lowercase
$string = "This is the best sentence ever! Winning!";
$string = strtolower($string);
$string = preg_replace('/[^\w\d_ -]/si', '', $string);
$lines = explode("\n", file_get_contents("wordlist.txt"));
$words = explode(" ", $string);
foreach ($lines as $line) {
$split = preg_split("/(\#|\t)/", $line); //split on # or tab
$words[$split[0]] = array_pop($split);
//split[0] (first element) contains the word
//array_pop (last element) contains score
echo array_pop($split);
}
//do whatever
echo $words["best"] + $words["inlaid"] + $words["laziness"];
?>