Các hàm validate sử dụng RegExp

Kiểm tra là 1 xâu là chỉ gồm chữ hoặc số?function isAlphabetNumber($st){
if (ereg('^[a-z|A-Z|0-9]+$', $st)){
return 1;
}else{
return 0;
}
}

Kiểm tra 1 xâu có phải là dạng URL hay không?

function isUrl($url, $maxlen = 256){
if (strlen($url) > $maxlen) {
return 0;
}
if(ereg("(h{0,1}t{0,2}p{0,1}:{0,1}/{0,1}/{0,1})(w{0,3}\.{0,1})([aA-zZ]+)?\.{1}([aA-zZ]{2,3})(.*)", $url)){
return 1;
}
return 0;
}

Read the rest of this entry »

Share This Post

Xoá comment = Regular Expression

Xoá HTML Comment


preg_replace('/<!--(.|\s)*?-->/', '', $buffer);

Xoá PHP Comment


$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);

Share This Post