php 面试题详解

来源:互联网 发布:tomcat apache 编辑:程序博客网 时间:2024/06/07 23:26

// 获取文件后缀名

public function extension($str){

if (strstr($str, '?')) {
$file = strstr($str, '?', true); 
} else {
$file = $str;
}

$len = strrpos($file, '/') +  1;
$filename = substr($file, $len);

$res = explode('.', $filename);
return array_pop($res);

}





public function nformat($number)
{
$tmp = '';
$len = strlen($number);
$k = $len % 3;

for ($i = 0; $i < $len; $i++) {
if (($i % 3) == $k && $i !=0) {
$tmp .= ',';
}
$tmp .= $number[$i]; 
}
return $tmp;
}





$num = 0;
$str = 'http://www.baidu.com/abc/php/python/demo.php';
$newStr = str_replace(array('php', 'baidu'), array('python', 'showame'), $str, $num);
$code = '<a href="www.baidu.com">百度</a><font color="red">哪里有问题</font>';
$html = '/\<[\/\!]*?[^\<\>]*?\>/is';
$arr = array('123', '456', '789', '0123');
$replade = preg_replace($html, '', $code);
echo $str.'<br/>';
echo $newStr.'<br/>';
echo $replade.'<br/>';
echo $num.'<br/>';

如果你觉得我的文章对你有帮助,就请博主喝杯咖啡吧


原创粉丝点击