php字符串替換函數「獲取php獲取字符串第一個字符」

1、

$A="Hello "; 
functionprint_A() 
{
 $A = "phpmysql !!";
global $A; global 全局變量 函數是獨立的模塊 $A外界定義的
echo $A;
}
echo $A; //Hello
print_A(); //Hello 在你將$A定義為全局變量的時候,並未修改$A的值

2、

$email = 『langwan@thizlinux.com.cn』; 
$str = ___strstr_($email,『@』);
$info = __explode__(『.』,$str);
___print_r_($info);
輸出結果為:
Array ([0] => @thizlinux [1]=>com[2]=>cn) 輸出結果是一個數組

3、定義一個404跳轉

header("Http/1.1 404 Not Found");

5、不用PHP函數實現字符串反轉

Notice: Uninitialized string offset: 7 in D:\wamp\www\phpTest\test.php on line 7 //數組越界的問題
$str = 'abcdefg';
$len = strlen($str);
$return = '';
for($i=$len-1;$i>=0;$i--){
 $return.=$str{$i};
}
echo $return;

6、寫出五種獲取.jpg或者jpg的的方法

$dir = 'Uploads/img.upload.jpg';
substr($str,-3);
//echo substr($dir,strrpos($dir,'.'));
//echo strrchr($dir,'.');
//$arr = explode('.',$dir);
//print_r(array_pop($arr));
//$p = pathinfo($dir);
//print_r($p);
//print_r($p['extension']);
//$new_str = strrev($dir);
//echo $new_str."\n";
//$a = strrev(substr($new_str,0,strpos($new_str,'.')));
//echo $a;

7、請寫一個函數,實現以下功能: 字符串「open_door」 轉換成 「OpenDoor」、」make_by_id」 轉換成 」MakeById」

function o($str){
 $arr = explode('_',$str);
 $str = '';
 foreach($arr as $v){
 $str.=ucfirst($v);
 }
 return $str;
}
echo o('make_by_id');

方法2:

function ucfirstTest($str){
 return ucfirst($str);
}
function test($str){
 $arr = explode('_',$str);
 $new_arr = array_map('ucfirstTest',$arr);
 $str = implode('',$new_arr);
 return $str;
}
$str = 'open_str';
echo test($str);

8、用PHP打印出前一天的時間格式是2006-5-10 22:21:21(2分)

echo date('Y-m-d H:i:s',strtotime('-1 days'));
9、mb_substr($str,1,10,'utf-8');
10、修改session的生存時間
session_set_cookie_params

11、strpos====這裡要注意的就是strpos返回的是0,因為他在第0,所以要用===判斷

$str = 'https://www.baidu.com';
$str1 = 'https://';
print_r(strpos($str,$str1));
if(strpos($str,$str1) !== false){
	
}

12、下面輸出是什麼,主要考的就是運算符的優先級和++ –的問題

$x = 5;
echo $x; 5
echo "<br />";
echo $x+++$x++; 5+6 = 11
echo "<br />";
echo $x; 11
echo "<br />";
echo $x---$x--; 7-6 = 1
echo "<br />";
echo $x; 5

13、array_merge合併的時候,傳入的都是數組,如果一個不是數組就會返回null

14、$x = true and false; var_dump($x); true

15、PHP的可變變量:$a = c; $$a = 10; $c = 10;

<form action="test.php" method="post">
 <input type="text" name="a" id=""/>
 <input type="text" name="b" id=""/>
 <input type="submit" value="aa"/>
</form>
foreach($_POST as $k=>$v){
 ${$k} = $v;
}
echo 'a'.isset($a)?$a:''.PHP_EOL;
echo 'b'.isset($b)?$b:''.PHP_EOL;

16、什麼是自連接:無限分類就是自己鏈接自己查詢

17、html動態生成的節點加點擊事件

	$(".h3").on("click","h3",{foo:"文本:"},function(event){
    alert(event.data.foo+this.textContent);
  });

18、$url = ‘
http://www.test.com.cn/abc/de/fg.php?id=1′; 獲取php或者.php

$b = parse_url($url); //php解析url地址,parse_str是解析字符串parse_str($str,$out)
echo "<pre>";
/**array(4) {
["scheme"]=>
 string(4) "http"
 ["host"]=>
 string(15) "www.test.com.cn"
 ["path"]=>
 string(14) "/abc/de/fg.php"
 ["query"]=>
 string(4) "id=1"
}
 */
$arr = $b['path']; ///abc/de/fg.php
echo substr($arr,strpos($arr,'.'));
$new_arr = explode('.',$arr);
echo end($new_arr);
高效
$arr = parse_url('http://www.sina.com.cn/abc/de/fg.php?id=1');
$result=pathinfo(arr['path']);var_dump($arr);
array(4) { ["dirname"]=> string(7) "/abc/de" ["basename"]=> string(6) "fg.php" ["extension"]=> string(3) "php" ["filename"]=> string(2) "fg" }
var_dump($result['extension']);

19、mkdir和is_dir的使用

$dir = './liuzhu/test/';
if(is_dir($dir)){ //如果存在就返回true
 file_put_contents($dir.'1.txt',$url);
}else{ //如果不存在就創建,true的這個參數是可以循環創建
 if(mkdir($dir,0777,true)){
 file_put_contents($dir.'1.txt',$url);
 };
}

20、定義一個字符串,然後獲取第一個字符

$str = 'abcdef'; $one = $str[1] || $str{1} 這兩種方式

21、下面輸出no

$v = 1;
$m = 2;
$l = 3;
if( $l > $m > $v){
 echo "yes";
}else{
 echo "no";
}

首先$l>$m返回的是一個true 然後true>1 就返回了null

22、獲取圖片的信息

getimagesize () 獲取圖片的尺寸
Imagesx () 獲取圖片的寬度
Imagesy () 獲取圖片的高度
23、$_SERVER;
$host = $_SERVER['HTTP_HOST']; //localhost
$self = $_SERVER['PHP_SELF']; ///phpTest/test.php
echo $host.$self; //localhost/phpTest/test.php
echo $_SERVER['REMOTE_ADDR']; //客戶端ip地址
echo $_SERVER['SERVER_ADDR']; //服務端ip地址
echo $_SERVER['REQUEST_URI']; ///phpTest/test.php

24、php.ini 中safe mod關閉 影響哪些函數和參數,至少寫6個?

move_uploaded_file() exec()
system() passthru()
popen() fopen()
mkdir() rmdir()
rename() unlink()
copy() chgrp()
chown() chmod()
touch() symlink()
link() parse_ini_file()
set_time_limit() max_execution_time mail()

25、isset() 、empty()與is_null的區別

1、當變量未定義時,is_null() 和「參數本身」是不允許作為參數判斷的,會報Notice警告錯誤;

2、empty , isset首先都會檢查變量是否存在,然後對變量值進行檢測。而is_null 和 「參數本身」只是直接檢查變量值,是否為null,因此如果變量未定義就會出現錯誤!

3、isset():僅當null和未定義,返回false;

4、empty():””、0、”0″、NULL、FALSE、array(),未定義,均返回true;

5、is_null():僅判斷是否為null,未定義報警告;

6、變量本身作為參數,與empty()一致,但接受未定義變量時,報警告;

26、http_build_query()

$arr = [
 'title'=>'nihao',
 'content'=>'world'
];
$str = http_build_query($arr);
var_dump($str);

27、curl file_get_contents() socket三種方式實現提交數據

28、var_dump(((bool)’all’)+1); 2 true=1 1+1=2

29、如果你一個整型integer超出了範圍,那麼就會被轉成float

30、如果你定義的了一個數組,那麼當你unset這個數組的時候,你又定義了一個$a[5] 那麼這個鍵應該是從5開始

31、如何保證你的api接口的安全性

32、這個地方考察是先用後加的問題

$a = 3;
$b = 5;
if($a == 3 || $b == 7){
 echo $a++;
 echo $b++;
}
echo $a.' '.$b;
3 5 4 6

33、count除去數組和實例化對象 其他的count()都是1 null是0

$a = count([4,5,6])+count(null)+count(false);
var_dump($a);

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/273399.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-17 14:05
下一篇 2024-12-17 14:05

相關推薦

發表回復

登錄後才能評論