preg_match 如果制表符在字符串末尾

preg_match if tabulator at end of string

如何检查字符串末尾是否有制表符?哪种模式有效?我试过 /\+t$/ 但我得到 "There is NO tab at the end of the string" 即使最后有一个制表符。

<?php
$text = "Come to the dark side. We have cookies    ";
$pattern = "/\+t$/";

if(preg_match($pattern , $text)) 
{
   echo "There is a tab at the end of the string";
} 
else 
{
   echo "There is NO tab at the end of the string";
}
?>

您的正则表达式 /\+t$/ 匹配 + 符号后跟字符串末尾的字符 t

我猜你想要:

  • /\t$/ : 字符串末尾的制表
  • /\t+$/ : 最后一个或多个表格