{ $resultArray = array(); $num = 0; foreach ($listOfWords as $val) { $string = substr($val, 0, 1); if ($string == $startCharacter) { $resultArray[$num] = $val; $num++; } } return $resultArray; } ?> <ol> <?php $searchedWords = getWordsByCharacter($file_explode, 'C'); foreach ($searchedWords as $val) { $string = explode("\t", $val); ?> <li> <?php echo $string[0]; ?> - <?php echo $string[1]; ?> </li> <?php } ?> </ol> </div>
<h2>Searching Words</h2> <!-- Ex. 3: Searching Words & Ex 6: Query Parameters --> <?php function getWordsByCharacter($listOfWords, $startCharacter) { $resultArray = array(); foreach ($listOfWords as $element) { if ($element[0] === $startCharacter) { $resultArray[] = $element; } } // $resultArray = array_filter($listOfWords, $startCharacter); return $resultArray; } $startCharacter = 'C'; $searchedWords = getWordsByCharacter($lines, $startCharacter); ?> <p> Words that started by <strong>'C'</strong> are followings : </p> <ol> <?php foreach ($searchedWords as $element) { ?> <li><?php echo $element; ?> </li> <?php } ?>
function getWordsByCharacter($listOfWords, $startCharacter) { $resultArray = array(); // implement here. foreach ($listOfWords as $key => $value) { if ($key[0] == $startCharacter) { array_push($resultArray, array($key, $value)); } } return $resultArray; } $startCharacter = $_GET["character"]; if (!isset($startCharacter) || strlen($startCharacter) == 0) { $startCharacter = "C"; } $searchedWords = getWordsByCharacter($dictionary, $startCharacter); ?> <p> Words that started by <strong>'<?php echo $startCharacter; ?> '</strong> are followings : </p> <ol> <?php foreach ($searchedWords as $sWord) { ?> <li><?php echo $sWord[0]; ?> - <?php
return $resultArray; } $character = $_GET["character"]; if (!isset($character) or $character == "") { $character = "C"; } ?> <p> Words that started by <strong>'<?php echo $character; ?> '</strong> are followings : </p> <ol> <?php $resultArray = getWordsByCharacter($file, $character); foreach ($resultArray as $line) { ?> <li><?php echo $line; ?> </li> <?php } ?> </ol> </div> <div class="section"> <h2>List of Words</h2> <!-- Ex. 4: List of Words & Ex 6: Query Parameters --> <?php
<h2>Searching Words</h2> <!-- Ex. 3: Searching Words & Ex 6: Query Parameters --> <?php function getWordsByCharacter($listOfWords, $startCharacter){ $resultArray = array(); foreach ($listOfWords as $row) { if($row[0] == $startCharacter) { array_push($resultArray, $row); } } return $resultArray; } $searchChar = 'D'; $res = getWordsByCharacter($line, $searchChar); ?> <p> Words that started by <strong><?=$searchChar?></strong> are followings : </p> <ol> <?php foreach($res as $row) {?> <li><?=$row;?></li> <? } ?> </ol> </div> <div class="section"> <h2>List of Words</h2>
{ $resultArray = array(); // implement here. foreach ($listOfWords as $word) { $tmp = explode("\t", $word); $index = strpos($tmp[0], $startCharacter); if (substr($tmp[0], 0, 1) == $startCharacter) { $resultArray[] = $word; } } return $resultArray; } if (isset($_GET["character"])) { $searchedWords = getWordsByCharacter($lines, $_GET["character"]); } else { $searchedWords = getWordsByCharacter($lines, "C"); } ?> <p>Words that started by <strong><?php echo $_GET["character"]; ?> </strong> are followings : </p> <ol> <?php foreach ($searchedWords as $word) { $tmp = explode("\t", $word); ?> <li><?php echo $tmp[0]; ?> - <?php
$resultArray = array(); foreach ($listOfWords as $temp) { if (substr($startCharacter, 0, 1)) { $resultArray = $temp; } } return $resultArray; } ?> <p> Words that started by <strong>'C'</strong> are followings : </p> <ol> <?php echo getWordsByCharacter(getWordsByNumber($lines, $numberOfWords), $startCharacter); foreach (getWordsByCharacter($getWordsByNumber, $startCharacter) as $searchedWords) { ?> <li><?php echo $searchedWords; ?> </li> <?php } ?> </ol> </div> <div class="section"> <h2>List of Words</h2> <!-- Ex. 4: List of Words & Ex 6: Query Parameters --> <?php