我的网站是用PHP编写的,这是我有的代码
//good words
$body = implode(" ", $body_array);
$niceWords = array("nice", "amazing", "fantastic", "great");
$body = preg_replace('/\b('.implode('|',$niceWords).')\b/','You have used the speical ',$body);
//Start the Points
$_SESSION['points'];
$_SESSION['points']++;
echo $_SESSION['points'];
答案 0 :(得分:0)
<?php session_start(); ?>
<form method="POST">
<input type="text" size="60" name="myText" id="myText" />
<input type="submit" name="submit" value="submit" />
</form>
<?php
if(isset($_POST["submit"])) {
//echo "$_POST[myText] <br>";
$niceWords = array("nice", "amazing", "fantastic", "great");
$textArray = explode(" ", $_POST["myText"]); // create an array of all the words from the textbox
if(! isset($_SESSION["points"])) {
//Start the Points
$_SESSION["points"] = 0;
}
foreach($textArray as $word) {
//echo "$word <br/>";
// check if the word is in the array of niceWords
if(in_array($word, $niceWords)) {
//echo "Yeah!! nice word... <br/>";
// if it is in the array increment points counter
$_SESSION["points"]++;
}
}
echo $_SESSION['points'];
}
?>