Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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正则表达式_Php - Fatal编程技术网

在数组中查找问号的Php正则表达式

在数组中查找问号的Php正则表达式,php,Php,我想检查数组值是否包含“?”。如果是,则必须提取问号后面的字符。多谢各位 这是我的密码: <?php // Assume the Url to be localhost/demo/index.php?set=1 $path = explode('/',$_SERVER['REQUEST_URI']); if (strpos($path[2], '?') !== false) { echo "found"; } ?> 如何使用preg\u match实现同样的效果?使用数组()中

我想检查数组值是否包含“?”。如果是,则必须提取问号后面的字符。多谢各位

这是我的密码:

<?php
// Assume the Url to be localhost/demo/index.php?set=1
$path = explode('/',$_SERVER['REQUEST_URI']);
if (strpos($path[2], '?') !== false) {
echo "found";
}
?>


如何使用preg\u match实现同样的效果?

使用数组()中的
。。比正则表达式快得多

<?php

$a = array('1','?','3');
$needle = '?';
if(in_array($needle,$a))
{
    echo $needle;

}

是数组还是字符串?在数组中,不相似的字符被聚在一起。假设你是指一根绳子,你可以试试

<?php

$haystack="testata?basdasd";
$needle="?";

 $pos = strpos($haystack,$needle);
 if($pos!==FALSE && $haystack[$post+1]!="")
  echo $haystack[$pos+1];

?>

假设您的问题的意思是,如果在数组中的字符串中有“?”字符:

没有正则表达式:

<?php
   for($i = 0; $i < count($array); $i++) {
     if (strpos($array[$i], '?') !== false) {
       // you found your item, use the $i index and break the loop
     }
   }
?>
<?php
   for($i = 0; $i < count($array); $i++) {
     if (preg_match('/\?/', $array[$i])) {
       // you found your item, use the $i index and break the loop
     }
   }
?>

对于正则表达式:

<?php
   for($i = 0; $i < count($array); $i++) {
     if (strpos($array[$i], '?') !== false) {
       // you found your item, use the $i index and break the loop
     }
   }
?>
<?php
   for($i = 0; $i < count($array); $i++) {
     if (preg_match('/\?/', $array[$i])) {
       // you found your item, use the $i index and break the loop
     }
   }
?>


$storedText是一个数组,其中所有文本都继承了?在所有包含?

的值中,这个问题似乎是离题的,因为它与php文档中的内容有关,这个特定的问题将来可能对任何人都没有帮助。