-
- function GBsubstr($string, $start, $length) {
- if(strlen($string)>$length){
- $str=null;
- $len=$start $length;
- for($i=$start;$i<$len;$i ){
- if(ord(substr($string,$i,1))>0xa0){
- $str.=substr($string,$i,2);
- $i ;
- }else{
- $str.=substr($string,$i,1);
- }
- }
- return $str.'...';
- }else{
- return $string;
- }
- }
复制代码
2.用PHP写出显示客户端IP与服务器IP的代码?
答:
-
- $readcontents = fopen("http://bbs.it-home.org/index.html", "rb");
- $contents = stream_get_contents($readcontents);
- fclose($readcontents);
- echo $contents;
-
复制代码
方法2:
-
- function getExt($url){
- $arr = parse_url($url);
-
- $file = basename($arr['path']);
- $ext = explode(".",$file);
- return $ext[1];
- }
-
复制代码
答案2:
-
- function getExt($url) {
- $url = basename($url);
- $pos1 = strpos($url,".");
- $pos2 = strpos($url,"?");
- if(strstr($url,"?")){
- return substr($url,$pos1 1,$pos2 - $pos1 - 1);
- } else {
- return substr($url,$pos1);
- }
- }
复制代码
19. 写一个函数,算出两个文件的相对路径?
如 $a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
计算出 $b 相对于 $a 的相对路径应该是 http://bbs.it-home.org/c/d将()添上
答:
-
- function getRelativePath($a, $b) {
- $returnPath = array(dirname($b));
- $arrA = explode('/', $a);
- $arrB = explode('/', $returnPath[0]);
- for ($n = 1, $len = count($arrB); $n < $len; $n ) {
- if ($arrA[$n] != $arrB[$n]) {
- break;
- }
- }
- if ($len - $n > 0) {
- $returnPath = array_merge($returnPath, array_fill(1, $len - $n, '..'));
- }
-
- $returnPath = array_merge($returnPath, array_slice($arrA, $n));
- return implode('/', $returnPath);
- }
- echo getRelativePath($a, $b);
复制代码
希望以上为大家提供的php面试题,对大家有所帮助,真诚期待在您的应聘中可以用得上。
|