更新:计算出了
答:我想明白了。
在每个角色之后都隐藏了\0。
解决办法很简单:
trim(str_replace("\0", '', $string))ASCII产出:
|0()|84(T)|0()|104(h)|0()|101(e)|0()|32( )|0()|110(n)|0()|117(u)|0()|109(m)|0()|98(b)|0()|101(e)|0()|114(r)|0()|32( )|0()|111(o)|0()|102(f)|0()|32( )|0()|112(p)|0()|101(e)|0()|110(n)|0()|100(d)|0()|105(i)|0()|110(n)|0()|103(g)|0()|32( )|0()|100(d)|0()|101(e)|0()|118(v)|0()|105(i)|0()|99(c)|0()|101(e)|0()|40(()|0()|115(s)|0()|41())|0()|32( )|0()|105(i)|0()|115(s)|0()|32( )|0()|48(0)|0()|46(.)|0()|13(
)|0()|问题:
下面是我正在测试的字符串的一个很好的例子:
$string =“挂起设备的数目为1”;
字符串(73)“挂起设备的数目为1。
我试图运行的代码是:
$string = "the number of pending device(s) is 1.";
if(strstr($string, "pending"))
{
echo "Found";
}另一个我一直在测试的是:
$text = "The number of pending device(s) is 1.";
$re1='.*?'; # Non-greedy match on filler
$re2='(?:[a-z][a-z]+)'; # Uninteresting: word
$re3='.*?'; # Non-greedy match on filler
$re4='(?:[a-z][a-z]+)'; # Uninteresting: word
$re5='.*?'; # Non-greedy match on filler
$re6='(?:[a-z][a-z]+)'; # Uninteresting: word
$re7='.*?'; # Non-greedy match on filler
$re8='((?:[a-z][a-z]+))'; # Word 1
$re9='.*?'; # Non-greedy match on filler
$re10='(\\d+)'; # Integer Number 1
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7.$re8.$re9.$re10."/is", $text, $matches))
{
$word1=$matches[1][0];
$int1=$matches[2][0];
print "($word1) ($int1) \n";
}现在,如果它只是一个字符串,这就很好了。我从windows提示符中提取数据,我可以很好地回显数据,但不幸的是,当我试图通过preg_match_all或strpos或strstr运行数据时,它总是返回false。这可能是编码问题吗?所有的数据都会回响到浏览器中。
请帮帮我!
发布于 2012-04-26 23:52:13
如您的示例所示,strstr()和preg_match_all()都工作得很好。因此,除了推测之外,我们什么也做不了。
由于正在读取的shell输出有问题,关键是该字符串与测试字符串之间的区别,所以您需要编辑这个问题或问一个新问题,提供代码“从windows DOS提示符中提取数据”。
此外,“回显到浏览器中”也不是检查字符串的好方法。试着读取各个字节。(我通常使用for循环、十六进制编辑器或数据包捕获实用程序。)
https://stackoverflow.com/questions/10342324
复制相似问题