-
- 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 ;
- }
- }
Copy the code
2. Use PHP to write the code to display the client IP and server IP?
Answer:
-
- $readcontents = fopen("http://bbs.it-home.org/index.html", "rb");
- $contents = stream_get_contents($readcontents);
- fclose($ readcontents);
- echo $contents;
-
Copy code
Method 2:
-
- function getExt($url){
- $arr = parse_url($url);
-
- $file = basename($arr['path']);
- $ext = explode(".",$ file);
- return $ext[1];
- }
-
Copy code
Answer 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) ;
- }
- }
Copy code
19. Write a function to calculate the relative paths of two files?
For example $a = '/a/b/c/d/e.php';
$b = '/a/b/12/34/c.php';
Calculate that the relative path of $b relative to $a should be http://bbs.it-home.org/c/d and add ()
Answer:
-
- 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 );
Copy code
I hope the above PHP interview questions provided for you will be helpful to you, and I sincerely hope that they can be used in your application.
|