吳曠明
//主要用到php的in_array函數,代碼示例如下$tids= array ( 2=> '19', 3 => '13', );$ids=array ( 0 => '96', 1 => '116', 2 => '13', 3 => '19' );$flag=true;foreach($tids as $v){ if(!in_array($v,$ids)){ $flag=false; break; }}if($flag){ echo '$b數組包含$a數組';}else{ echo '$b數組不包含$a數組';}
文詠珊
可以,但是需要修改配置程序。具體如下:最好檢查一下php.ini中的配置選項allow_url_include,如果為on則可以包含,否則不能包含; Whether to allow include/require to open URLs (like http:// or ftp://) as files.allow_url_include = Off做個簡單的測試,此時allow_url_include的值為Off測試前配置一下hosts文件,這樣可以在一臺電腦上面進行模擬測試192.168.1.101 www.test1.com192.168.1.102 www.test2.compath.php文件內容為:<?phpecho "This is file path.php<br />\n";include("http://www.test2.com/research/path/path.php");?>path1.php文件內容為:<?phpecho "This is file path1.php in root directory\n";?>執(zhí)行http://www.test1.com/research/path/path.php,輸出如下This is file path.phpWarning: include() [function.include]: URL file-access is disabled in the server configuration in E:\myphp\research\path\path.php on line 3Warning: include(http://www.test2.com/research/path/path.php) [function.include]: failed to open stream: no suitable wrapper could be found in E:\myphp\research\path\path.php on line 3Warning: include() [function.include]: Failed opening 'http://www.test2.com/research/path/path.php' for inclusion (include_path='.;C:\php5\pear') in E:\myphp\research\path\path.php on line 3將php.ini中的allow_url_include改為On,重新啟動web服務器,再次執(zhí)行http://www.test1.com/research/path/path.php,輸出如下:This is file path.phpThis is file path1.php in root directory 將allow_url_include設為On以后,就可以包含遠程文件了,并且包含的是遠程文件執(zhí)行的結果。
李繼中
<?php$str1 = 'ABCDE';$str2 = 'AE';var_dump(in_str($str2, $str1));function in_str($needle, $haystack){ for($i = 0; $i < strlen($needle); $i++) { for($j = 0; $j < strlen($haystack); $j++) { if($needle{$i} == $haystack{$j}) { continue 2; } } return false; } return true;}?>
雨花崖
<?include('../login.php');?>//要先退回上一級目錄才能調用上一級目錄中的文件,退回上一級目錄用../,退回多少級用多少../;<?include('../manage/index.php');?>//只要不在同一文件夾中,如果兩個文件夾是在同一級,那么先要退回上一級文件夾,然后再進入到另一文件夾中,才能調用另一文件夾中的文件
小哪吒
有這樣的函數:array_search — 在數組中搜索給定的值,如果成功則返回相應的鍵名
函數參數說明:
mixed array_search ( mixed $needle , array $haystack [, bool $strict ] )
在 haystack 中搜索 needle 參數并在找到的情況下返回鍵名,否則返回 FALSE。
備注:
如果 needle 是字符串,則比較以區(qū)分大小寫的方式進行。
例子:
<?php$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');$key = array_search('green', $array); // $key = 2;$key = array_search('red', $array); // $key = 1;?>我想要利用數組去搜索字符串,就是查找字符串中有沒有出現(xiàn)過數組中的內容!并不是檢索數組!
那只有使用循環(huán)了。
銀樓金粉
strpos — 查找字符串首次出現(xiàn)的位置$mystring = 'abc';$findme = 'a';$pos = strpos($mystring, $findme);// 注意這里使用的是 ===。簡單的 == 不能像我們期待的那樣工作,// 因為 'a' 是第 0 位置上的(第一個)字符。if ($pos === false) {echo "The string '$findme' was not found in the string '$mystring'";} else {echo "The string '$findme' was found in the string '$mystring'";echo " and exists at position $pos";}
魏瑤芝
這需要用到正則preg_match('/[\x{4e00}-\x{9fa5}]/u', $str)這個可以匹配字符串中是否有中文,沒有的話返回0【TSD。M】
美麗人生
PHP中如何判斷一個字符串中是否有某個字符,如下:PHP語言是一個功能強大的嵌入式HTML腳本語言,它的易用性讓許多程序員選擇使用。PHP判斷字符串的包含,可以使用PHP的內置函數strstr,strpos,stristr直接進行判斷.也可以通過explode函數的作用寫一個判斷函數。1. strstr: 返回一個從被判斷字符開始到結束的字符串,如果沒有返回值,則不包含代碼如下:< ?php /*如手冊上的舉例*/ $email = 'user@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com ?> 2. stristr: 它和strstr的使用方法完全一樣.唯一的區(qū)別是stristr不區(qū)分大小寫.3. strpos: 返回boolean值.FALSE和TRUE不用多說.用 “===”進行判斷.strpos在執(zhí)行速度上都比以上兩個函數快,另外strpos有一個參數指定判斷的位置,但是默認為空.意思是判斷整個字符串.缺點是對中文的支持不好. PHP判斷字符串的包含代碼如下:$str= 'abc'; $needle= 'a'; $pos = strpos($str, $needle); 4. 用explode進行判斷 PHP判斷字符串的包含代碼如下:function checkstr($str){ $needle = "a";//判斷是否包含a這個字符 $tmparray = explode($needle,$str); if(count($tmparray)>1){ return true; } else{ return false; } }
鄭倫
php如何判斷一個字符串是否包含另一個字符串 我覺得最簡單的就是: strpos($a, $b) !== false 如果$a 中存在 $b,則為 true ,否則為 false。 用 !== false (或者 === false) 的原因是如果 $b 正好位于$a的開始部分,那么該函數會返回int(0),...