function makeNowPlaying() { global $plex_instances; foreach ($plex_instances as $instance) { $plex_port = $instance[1]; $network = getNetwork($instance[3]); $clientIP = get_client_ip(); $plexSessionXML = simplexml_load_file($network . ':' . $plex_port . '/status/sessions'); if (!$plexSessionXML) { makeRecenlyViewed(); } elseif (count($plexSessionXML->Video) == 0) { makeRecenlyReleased(); } else { $i = 0; // Initiate and assign a value to i & t $t = 0; // T is the total amount of sessions echo '<div class="col-md-10 col-sm-offset-1">'; //echo '<div class="col-md-12">'; foreach ($plexSessionXML->Video as $sessionInfo) { $t++; } foreach ($plexSessionXML->Video as $sessionInfo) { $mediaKey = $sessionInfo['key']; $playerTitle = $sessionInfo->Player['title']; $mediaXML = simplexml_load_file($network . ':' . $plex_port . $mediaKey); $type = $mediaXML->Video['type']; echo '<div class="thumbnail">'; $i++; // Increment i every pass through the array if ($type == "movie") { // Build information for a movie $movieArt = $mediaXML->Video['thumb']; $movieTitle = $mediaXML->Video['title']; $duration = $plexSessionXML->Video[$i - 1]['duration']; $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset']; $progress = sprintf('%.0f', $viewOffset / $duration * 100); $user = $plexSessionXML->Video[$i - 1]->User['title']; $device = $plexSessionXML->Video[$i - 1]->Player['title']; $state = $plexSessionXML->Video[$i - 1]->Player['state']; // Truncate movie summary if it's more than 50 words if (countWords($mediaXML->Video['summary']) < 51) { $movieSummary = $mediaXML->Video['summary']; } else { $movieSummary = limitWords($mediaXML->Video['summary'], 50); // Limit to 50 words $movieSummary .= "..."; // Add ellipsis } echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $movieArt) . '" alt="' . $movieTitle . '">'; // Make now playing progress bar //echo 'div id="now-playing-progress-bar">'; echo '<div class="progress now-playing-progress-bar">'; echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">'; echo '</div>'; echo '</div>'; echo '<div class="caption">'; //echo '<h2 class="exoextralight">'.$movieTitle.'</h2>'; echo '<p class="exolight" style="margin-top:5px;">' . $movieSummary . '</p>'; if ($state == "playing") { // Show the playing icon echo '<span class="glyphicon glyphicon-play"></span>'; } else { echo '<span class="glyphicon glyphicon-pause"></span>'; } if ($user == "") { echo '<p class="exolight">' . $device . '</p>'; } else { echo '<p class="exolight">' . $user . '</p>'; } } else { // Build information for a tv show $tvArt = $mediaXML->Video['grandparentThumb']; $showTitle = $mediaXML->Video['grandparentTitle']; $episodeTitle = $mediaXML->Video['title']; $episodeSummary = $mediaXML->Video['summary']; $episodeSeason = $mediaXML->Video['parentIndex']; $episodeNumber = $mediaXML->Video['index']; $duration = $plexSessionXML->Video[$i - 1]['duration']; $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset']; $progress = sprintf('%.0f', $viewOffset / $duration * 100); $user = $plexSessionXML->Video[$i - 1]->User['title']; $device = $plexSessionXML->Video[$i - 1]->Player['title']; $state = $plexSessionXML->Video[$i - 1]->Player['state']; //echo '<div class="img-overlay">'; echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $tvArt) . '" alt="' . $showTitle . '">'; // Make now playing progress bar //echo 'div id="now-playing-progress-bar">'; echo '<div class="progress now-playing-progress-bar">'; echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">'; echo '</div>'; echo '</div>'; //echo '</div>'; // Make description below thumbnail echo '<div class="caption">'; //echo '<h2 class="exoextralight">'.$showTitle.'</h2>'; echo '<h3 class="exoextralight" style="margin-top:5px;">Season ' . $episodeSeason . '</h3>'; echo '<h4 class="exoextralight" style="margin-top:5px;">E' . $episodeNumber . ' - ' . $episodeTitle . '</h4>'; // Truncate episode summary if it's more than 50 words if (countWords($mediaXML->Video['summary']) < 51) { $episodeSummary = $mediaXML->Video['summary']; } else { $episodeSummary = limitWords($mediaXML->Video['summary'], 50); // Limit to 50 words $episodeSummary .= "..."; // Add ellipsis } echo '<p class="exolight">' . $episodeSummary . '</p>'; if ($state == "playing") { // Show the playing icon echo '<span class="glyphicon glyphicon-play"></span>'; } else { echo '<span class="glyphicon glyphicon-pause"></span>'; } if ($user == "") { echo '<p class="exolight">' . $device . '</p>'; } else { echo '<p class="exolight">' . $user . '</p>'; } } // Action buttons if we ever want to do something with them. //echo '<p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn btn-default">Action</a></p>'; echo "</div>"; echo "</div>"; // Should we make <hr>? Only if there is more than one video and it's not the last thumbnail created. if ($i > 0 && $i < $t) { echo '<hr>'; } else { // Do nothing } } echo '</div>'; } } }
<?php echo get_include_path(); echo "<br/>"; /*---------- Unit Test: WordCount test ----------*/ $sentence = "My name is John "; function countWords($sentence) { return count(preg_split('~\\s+~', $sentence)); } echo countWords($sentence);
$xoopsTpl -> assign ( 'lang_moduledirname', $xoopsModule->dirname() ); $xoopsTpl -> assign ( 'lang_config', intval($xoopsModuleConfig["allowsubmit"]) ); $xoopsTpl -> assign ( 'lang_home', constant("_MD_{$MYDIRNAME}_HOME") ); $xoopsTpl -> assign ( 'lang_seachhead', constant("_MD_{$MYDIRNAME}_SEARCHHEAD") ); $xoopsTpl -> assign ( 'lang_still', constant("_MD_{$MYDIRNAME}_STILLNOTHINGHERE") ); $xoopsTpl -> assign ( 'lang_1st', constant("_MD_{$MYDIRNAME}_READMEFIRST") ); $xoopsTpl -> assign ( 'lang_now', constant("_MD_{$MYDIRNAME}_NOW") ); $xoopsTpl -> assign ( 'lang_defs', constant("_MD_{$MYDIRNAME}_DEFS") ); $xoopsTpl -> assign ( 'lang_cats', constant("_MD_{$MYDIRNAME}_CATS") ); $xoopsTpl -> assign ( 'lang_seachent', constant("_MD_{$MYDIRNAME}_SEARCHENTRY") ); $xoopsTpl -> assign ( 'lang_rubyl', constant("_MD_{$MYDIRNAME}_RUBYL") ); $xoopsTpl -> assign ( 'lang_rubyr', constant("_MD_{$MYDIRNAME}_RUBYR") ); $xoopsTpl -> assign ( 'lang_yomi', constant("_MD_{$MYDIRNAME}_ENTRYYOMI") ); $xoopsTpl -> assign ( 'lang_letterdef', constant("_MD_{$MYDIRNAME}_LETTERDEFINS") ); $xoopsTpl -> assign ( 'lang_return', constant("_MD_{$MYDIRNAME}_RETURN") ); $xoopsTpl -> assign ( 'lang_index', constant("_MD_{$MYDIRNAME}_RETURN2INDEX") ); $xoopsTpl -> assign ( 'config_req', intval($xoopsModuleConfig["allowreq"]) ); $xoopsTpl -> assign ( 'amazon_id', $myts -> makeTboxData4Show($xoopsModuleConfig["amazon_id"] )); $xoopsTpl -> assign ( 'searchstring', $searchstring ); $xoopsTpl -> assign ( 'config_readme', $myts -> displayTarea($xoopsModuleConfig["readme1st"],1,1,1,1,1) ); $xoopsTpl -> assign ( 'titleblockuse', intval($xoopsModuleConfig["titleblockuse"]) ); $xoopsTpl -> assign ( 'h1id', $myts -> makeTboxData4Show( $xoopsModuleConfig["h1id"] ) ); $xoopsTpl -> assign ( 'searchform', showSearchForm($query,$type,$catID,$andor)); $xoopsTpl -> assign ( 'totalcats', countCats() ); $xoopsTpl -> assign ( 'publishedwords', countWords() ); $xoopsTpl -> assign ( 'intro', $intro ); $xoopsTpl -> assign ( 'multicats', $xoopsModuleConfig['multicats'] ); $xoopsTpl -> assign ( 'resultset', $resultset ); include(XOOPS_ROOT_PATH.'/footer.php'); ?>
</head> <body> <form action="index.php" method="post"> <p>Enter your text</p> <textarea name="userText" id="" cols="70" rows="10"></textarea><br><br><br> <input name="submit" type="submit" value="submit"><br><br> </form> </body> </html> <?php function countWords($text) { $words = explode(" ", $text); $wordsCounted = array_count_values($words); arsort($wordsCounted); foreach ($wordsCounted as $key => $value) { echo "{$key} - {$value}<br>"; } } if ($_POST) { if (isset($_POST['userText'])) { $text = $_POST['userText']; } if ($_POST['submit']) { if ($_POST['userText'] == null) { die("Enter text"); } } } countWords($text);
} } return $result; } function formatWordsAsTable($words) { $result = '<table><tbody>'; foreach ($words as $word => $count) { $result .= "<tr><td>{$word}</td><td>{$count}</td></tr>"; } return $result . '</tbody></table>'; } $result = ''; if (!empty($_GET['text'])) { $input = htmlentities($_GET['text']); $result = countWords($input); if (count($result) <= 0) { $result = 'No words found!'; } else { $result = formatWordsAsTable($result); } } ?> <!DOCTYPE html> <html> <head> <title>Word Mapping</title> <link rel="stylesheet" href="styles/style.css"/> </head> <body>
function validateAuthor($string) { return countWords($string) >= 2; }
<br><br><b> // String Function </b><br><br> <?php $myWord = 'This is Spartaaaa !'; function countWords() { global $myWord; echo 'Just Count : ' . str_word_count($myWord); echo '<br> Array : '; print_r(str_word_count($myWord, 1)); echo '<br> Associative Array : '; print_r(str_word_count($myWord, 2)); echo '<br> Counting ! symbol also : '; print_r(str_word_count($myWord, 2, '!')); } countWords(); ?> <br><br><b> // Create Random AlphaNum Code </b><br><br> <?php function createRandom() { $charCollection = '5317908462poiuytrejhbc!&%#'; echo str_shuffle($charCollection); } createRandom();
<!DOCTYPE html> <html> <head><title>Task 10</title></head> <body> <form action="" method="post"> <textarea name="text"></textarea> <input type="submit" name="submit"> </form> <?php if (isset($_POST['submit']) and isset($_POST['text'])) { echo countWords($_POST['text']); } ?> </body> </html> <?php function countWords($text) { $text = mb_strtolower($text); $wordArr = explode(" ", $text); $uniqueCount = 0; foreach ($wordArr as $v) { if (mb_strlen($v) and mb_substr_count($text, $v) == 1) { $uniqueCount++; } } return $uniqueCount; }