我想在wp中签入帖子内容是否包含gx-block类。例如我可以有class =“ something_can_exists_or_not gx-block something_else”应该打印true
class =“ gx-block” true等等。我已经尝试过了但是没用preg_match('/class="?.*gx-block?.*"/i', $content);
谢谢
您的regEx不正确。
您正在寻找字符串class="
,后跟任意数量的包含子字符串gx-block
的字符,后跟任意数量的字符。
preg_match('/class=".*gx-block.*"/i', '<div class="gx-block">abc</div>')