프로그래밍/PHP
php 정규식 문자열 체크
백룡화검
2009. 10. 23. 20:34
<?
// preg_match('/[0-9a-zA-Z.]+/', $FileName, $Result);
function test($ch) {
/*if(eregi("/^[a-z0-9_-]+$/i", $ch)) {
echo "ok";
}else{
//$pattern = "^[a-zA-Z0-9*|]";
//$replace_ch = preg_replace($pattern, '', $ch);
//echo $replace_ch;
echo "no";
} */
/*preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result , PREG_OFFSET_CAPTURE) ;
if($result[0][0] == $ch ){
echo "ok";
echo "<br>";
echo $ch;
echo "<br>";
}else{
preg_match('/[0-9a-zA-Z\*\|]+/', $ch ,$result1 , PREG_OFFSET_CAPTURE) ;
$rs = $result[0][0].$result1[0][0] ;
echo "no";
echo "<br>";
echo $result[0][0];
echo "<br>";
echo $result1[0][0];
echo "<br>";
echo $ch." ---> ".$rs;
}
*/
preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result) ;
if($result[0] == $ch ){
echo "ok";
echo "<br>";
echo $ch;
echo "<br>";
echo $result[0];
}else{
echo "no";
echo "<br>";
echo $result[0];
}
}
/*
function test($ch) {
preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result , PREG_OFFSET_CAPTURE) ;
if($result[0][0] == $ch ){
echo "ok";
echo "<br>";
print_r($result);
}else{
echo "no";
echo "<br>";
print_r($result);
}
}
*/
$id = "a!b123**||!*|*";
test($id);
?>
출처 : http://blog.shypepe.com/150021787717
// preg_match('/[0-9a-zA-Z.]+/', $FileName, $Result);
function test($ch) {
/*if(eregi("/^[a-z0-9_-]+$/i", $ch)) {
echo "ok";
}else{
//$pattern = "^[a-zA-Z0-9*|]";
//$replace_ch = preg_replace($pattern, '', $ch);
//echo $replace_ch;
echo "no";
} */
/*preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result , PREG_OFFSET_CAPTURE) ;
if($result[0][0] == $ch ){
echo "ok";
echo "<br>";
echo $ch;
echo "<br>";
}else{
preg_match('/[0-9a-zA-Z\*\|]+/', $ch ,$result1 , PREG_OFFSET_CAPTURE) ;
$rs = $result[0][0].$result1[0][0] ;
echo "no";
echo "<br>";
echo $result[0][0];
echo "<br>";
echo $result1[0][0];
echo "<br>";
echo $ch." ---> ".$rs;
}
*/
preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result) ;
if($result[0] == $ch ){
echo "ok";
echo "<br>";
echo $ch;
echo "<br>";
echo $result[0];
}else{
echo "no";
echo "<br>";
echo $result[0];
}
}
/*
function test($ch) {
preg_match('/[0-9a-zA-Z\*\|]+$/i', $ch ,$result , PREG_OFFSET_CAPTURE) ;
if($result[0][0] == $ch ){
echo "ok";
echo "<br>";
print_r($result);
}else{
echo "no";
echo "<br>";
print_r($result);
}
}
*/
$id = "a!b123**||!*|*";
test($id);
?>
출처 : http://blog.shypepe.com/150021787717