Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php stristr,如果字符串不包含任何内容(空字符串)_Php_String_Foreach_Contains_Isset - Fatal编程技术网

Php stristr,如果字符串不包含任何内容(空字符串)

Php stristr,如果字符串不包含任何内容(空字符串),php,string,foreach,contains,isset,Php,String,Foreach,Contains,Isset,我正在搜索我的网站,当某个特定参数为“”(无)时,我希望显示所有结果。我尝试了以下方法,但没有成功 <?php $a = file("test.txt"); sort($a); foreach ($a as $b) { $c = explode("|", $b); if (isset($_GET['name'])) { if (stristr($c[0], $_GET['name'])) { echo '<option value="' . $c[0] . '

我正在搜索我的网站,当某个特定参数为“”(无)时,我希望显示所有结果。我尝试了以下方法,但没有成功

<?php
$a = file("test.txt");
sort($a);
foreach ($a as $b) {
$c = explode("|", $b);
if (isset($_GET['name'])) {
    if (stristr($c[0], $_GET['name'])) {
        echo '<option value="' . $c[0] . '">' . $c[0] . '</option>';
    }
}
?>

这只是一个测试脚本,我将在上面的if语句中使用多个GET。

使用而不是isset。

使用而不是isset。

if(空($\u GET['name'])){
if (empty($_GET['name'])){
    echo '<option value="'.$c[0].'">'.$c[0].'</option>';
}
回显“.$c[0]”; }
if(空($\u GET['name'])){
回显“.$c[0]”;
}

检查stristr是否未返回false

if (stristr($c[0], $_GET['name']) != FALSE)

检查stristr是否未返回false

if (stristr($c[0], $_GET['name']) != FALSE)

您真的应该使用更多合适的变量名,而不是
$a
$b
$c
。例如,使用
$file
$line
$separated\u line
。您想在什么时候做什么?如果它已设置且为空?您真的应该使用更多正确的变量名,而不是
$a
$b
$c
。例如,使用
$file
$line
$separated\u line
。您想在什么时候做什么?如果设置好了,如果是空的?