更新:それを考え出した
答え: 分かった。
すべての文字の後に、隠れた \0 がありました。
修正は簡単です:
trim(str_replace("\0", '', $string))
アスキー出力:
|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 です。";
string(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 DOS プロンプトからデータを取得しており、データを正常にエコーアウトできますが、残念ながら preg_match_all または strpos または strstr を介してデータを実行しようとすると、常に false が返されます。これはエンコードの問題でしょうか? すべてのデータがブラウザにエコーアウトされます。
助けてください!