如何使用 PHP 中的 preg_match 检查字符串中是否存在特殊字符,如 ( >, < ,-, 0-9)

how to check the special chars like ( >, < ,-, 0-9) exists in string using preg_match in PHP

我只想使用 preg_match 检查包含(>、<、-、0-9)的字符串,如果存在 return 则为真。这是我的试用版:

   $page_num  ="25-100"; or $page_num = ">300";
  if (preg_match('/[0-9]+<+>/', $page_num))
  {
   return true;
  }

这应该可以解决问题:

^[0-9-<>]+$

这是正确的正则表达式:

if (preg_match('/[><\-0-9]/', $page_num))

如果你想检查是否所有字符都是其中之一(^$ 强制字符串从字符串的开头到结尾只包含这些字符):

if (preg_match('/^[><\-0-9]+$/', $page_num))