Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.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 使用数字范围搜索strpos()_Php_Iptables_Strpos - Fatal编程技术网

Php 使用数字范围搜索strpos()

Php 使用数字范围搜索strpos(),php,iptables,strpos,Php,Iptables,Strpos,我想在一个端口被阻止的字符串中搜索规则,iptables,并显示该端口 例如,规则iptables-A OUTPUT-ptcp-dport8080-j DROP我希望能够通过strpos字符串tcp--dport 8080-j DROP进行搜索,但搜索范围是1-65335,而不是8080 请原谅我英语不好。假设每个字符串都是固定格式的,就像您的示例一样,您可以搜索数字,然后使用函数检查是否在范围内 $str='iptables-A OUTPUT-ptcp-dport8080-jdrop;'; p

我想在一个端口被阻止的字符串中搜索规则,
iptables
,并显示该端口

例如,规则
iptables-A OUTPUT-ptcp-dport8080-j DROP
我希望能够通过
strpos
字符串
tcp--dport 8080-j DROP
进行搜索,但搜索范围是
1-65335,而不是8080


请原谅我英语不好。

假设每个字符串都是固定格式的,就像您的示例一样,您可以搜索数字,然后使用函数检查是否在范围内

$str='iptables-A OUTPUT-ptcp-dport8080-jdrop;';
preg_match('/\d+/',$str,$match);//搜索匹配项

如果($match[0]>=1&&$match[0]使用正则表达式来执行此操作,而不是使用strpos。如果需要更多帮助,请提供一个完整的、最少的示例。@DanFarrell我的目标是获取包含“tcp--dport 1-65355-j DROP”的字符串。例如“tcp--dport 8080-j DROP”或“tcp--dport 21-j DROP”向我们展示您迄今为止尝试了什么以及发生了什么,我们将帮助您找出解决方法。@DanFarrell我没有尝试太多,我使用了很多strpo,但不是在这个级别,所以我真的不知道该尝试什么。我是Sryan,我怎样才能获得带有数字的var?
$str = 'iptables -A OUTPUT -p tcp --dport 8080 -j DROP;';

preg_match('/\d+/', $str, $match); // search for matches
if ($match[0] >= 1 && $match[0] <= 65335) {
    echo "Valid number found on string";
}