Php替换为字符串Preg_match

问题描述 投票:0回答:1

我想在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);

谢谢

php regex wordpress preg-match
1个回答
0
投票

您的regEx不正确。

您正在寻找字符串class=",后跟任意数量的包含子字符串gx-block的字符,后跟任意数量的字符。

preg_match('/class=".*gx-block.*"/i', '<div class="gx-block">abc</div>')
© www.soinside.com 2019 - 2024. All rights reserved.