1. index.php
<?php
include "wordCheck.php";
if (isset($_POST['content']))
{
$wordCheck = new WordCheck;
$content = stripslashes($_POST['content']);
$exploded = $wordCheck->MultiExplode($content);
$wordList = $wordCheck->GetWordList($exploded);
$count = (count($wordList,1)/count($wordList,0))-1;
}
?>
<?php echo "Input " ?>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea rows="25" cols="60" name="content"></textarea>
<input type="submit" value="Save">
</form>
<textarea rows="35" cols="60" name="result">
<?php for($i=0; $i < $count; $i++)
{
echo "Word : " . $wordList[0][$i] . " " .
"Count : " . $wordList[1][$i] . "\n";
}
?></textarea>
<?php for($i=0; $i < $count; $i++)
{
echo "<a charset=UTF-8 href=http://endic.naver.com/search.nhn?sLn=kr&searchOption=all&query="
. $wordList[0][$i] . ">" . $wordList[0][$i] . "</a>" . "\n";
}
?>
2. wordCheck
<?php
class WordCheck
{
var $delimiters = array('\"', '?', '<', '>', '(', ')',
'!', '-', '/', ',', '.', '|',
'=', ':', ' ', "\r\n", "\t");
function MultiExplode($string)
{
$ready = str_replace($this->delimiters, $this->delimiters[0], $string);
$launch = explode($this->delimiters[0], $ready);
return $launch;
}
function GetWordList($exploded)
{
$count = array();
$word = array();
$unique = (array_unique($exploded));
foreach($unique as $token)
{
if (strcmp("\r\n", $token) == -1 || strcmp(" ", $token) == -1)
{
$countNum = count(array_keys($exploded, $token));
array_push($count, $countNum);
array_push($word, $token);
}
}
array_multisort($count, SORT_DESC,SORT_NUMERIC, $word, SORT_ASC, SORT_STRING);
return array($word, $count);
}
}
?>
2013년 12월 13일 금요일
2013년 12월 10일 화요일
PHP 단어 수 세는 소스
1. index.php
- vim /var/www/dwhan/index.php
<?php
include "wordCheck.php";if (isset($_POST['content'])){ $wordCheck = new WordCheck;$content = stripslashes($_POST['content']); $exploded = $wordCheck->MultiExplode($content); $wordList = $wordCheck->GetWordList($exploded);} ?><?php echo "Input " ?><form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"><textarea rows="25" cols="60" name="content"></textarea><input type="submit" value="Save"></form><textarea rows="35" cols="60" name="result"><?php foreach($wordList as $key => $value){foreach($value as $key => $value){echo "Word : " . $key . " " . "Count : " . $value . "\n";} }?></textarea>
2. wordCheck.php
- vim /var/www/dwhan/wordCheck.php
<?phpclass WordCheck{var $delimiters = array('\"', '?', '<', '>', '(', ')','!', '-', '/', ',', '.', '|', '=', ':', ' ', "\r\n", "\t");function MultiExplode($string){$ready = str_replace($this->delimiters, $this->delimiters[0], $string);$launch = explode($this->delimiters[0], $ready);return $launch;}function GetWordList($exploded){$word = array();$unique = (array_unique($exploded));foreach($unique as $token){if (strcmp("\r\n", $token) == -1 || strcmp(" ", $token) == -1){$count = count(array_keys($exploded, $token));$temp = array($token => $count); // 뽑아낸 단어와 카운트를 인덱스를 토큰으로 지정하여 배열에 저장array_push($word, $temp); // 생성한 배열을 추가}}return $word;}}?>
2013년 12월 4일 수요일
PHP ID, PW 이용
1. PHP 이용하여 인증 ID, PW 출력
<?php
echo "ID : "; echo $_SERVER['PHP_AUTH_USER']; echo "<br />"; // $_SERVER['PHP_AUTH_USER'] 변수는 인증 사용자를 표시해 주는 변수echo "PW : "; echo $_SERVER['PHP_AUTH_PW']; // $_SERVER['PHP_AUTH_PW'] 변수는 인증 사용자의 패스워드를 표시해 주는 변수
?>
2. Redirect
<?php
$id = $_SERVER['PHP_AUTH_USER'];
if($id == "admin") // 로그인한 아이디가 Admin 면 "Admin Page!" 출력
{
echo "Admin Page!";
}
else if($id == "test_cacti") // 로그인한 아이디가 test_cacti 면 Cacti 페이지로 리다이렉트
{
header("Location: http:// dwhan.no-ip.org:25040/cacti/") ;
}
else if($id == "test_blog") // 로그인한 아이디가 test_blog 면 WordPress 페이지로 리다이렉트
{
header("Location: http:// dwhan.no-ip.org:25040/ wordpress/");
}
?>
3. Page 표시
<?php$id = $_SERVER['PHP_AUTH_USER']; // 디렉토리 인증을 통과한 ID를 $id 변수에 대입if($id == "admin") // 로그인한 아이디가 admin 면 Cacti 링크, WordPress 링크 표시{echo "Admin Page!";echo '<a href="/cacti/index.php">Cacti</a> <br/>'; echo '<a href="/wordpress/index.php">WordPress</a> <br/>'; }else if($id == "test_cacti") // 로그인한 아이디가 test_cacti 면 Cacti 링크 표시{
echo '<a href="/cacti/index.php">Cacti</a>';
}else if($id == "test_blog") // 로그인한 아이디가 test_blog 면 WordPress 링크 표시{echo '<a href="/wordpress/index.php">WordPress</a>'; }?>
피드 구독하기:
글 (Atom)