Implementation to detect if there is a specific tag in html in php
1. When publishing a document to WeChat, WeChat response failed: error code: 45166, error message: Invalid content hint:[pzRHda0286d228]Rid: 61041ffe-5cefd269-6c9611ff.
2. The final analysis shows that the content of the document contains the label: Caused by MMPVoice. The content of the document is as follows:
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent
3. I finally decided to check whether there is a tag in the html before calling the WeChat interface: mpvoice, if it exists, then do not follow the follow-up process to save users waiting time
4. The final implementation code is as follows:
$mpvoicePattern = "/]+)>(?:(?!<\/mpvoice>)[\s\S])*<\/mpvoice>/s";
$audioPattern = "/]+)>(?:(?!<\/audio>)[\s\S])*<\/audio>/s";
preg_match($mpvoicePattern, $item['content'], $mpvoiceMatches);
preg_match($audioPattern, $item['content'], $audioMatches);
if (!empty($mpvoiceMatches)) {
$this->addError($attribute, Yii::t('error', Yii::t('error', Yii::t('error', '202247'), ['tag' => 'mpvoice'])));
break;
}
if (!empty($audioMatches)) {
$this->addError($attribute, Yii::t('error', Yii::t('error', Yii::t('error', '202247'), ['tag' => 'audio'])));
break;
}
5. Print $MPVOICEMATCHES and $AUDIOMATCHES respectively. The results are as follows
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentListen to the T-Rex:Your browser does not support theaudio element.
Array
(
[0] =>
[1] => class="js_editor_audio audio_iframe js_uneditable" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=%E4%B8%80%E4%B8%AA%E4%BA%BA%EF%BC%8C%E4%B9%9F%E6%8C%BA%E5%A5%BD&play_length=05:22" isaac2="1" low_size="612.81" source_size="612.8" high_size="2524.76" name="一个人,也挺好" play_length="322000" voice_encode_fileid="MzI1NjA0MDg2M18yNjUwNzYzNTcz" data-topic_id="1693506805106065417" data-topic_name="夜听精选" data-pluginname="insertaudio" style="margin-top: 50px; margin-right: 0px; margin-bottom: 0px; max-width: 100%;"
)
Array
(
[0] => Your browser does not support theaudio element.
[1] => controls src="/media/cc0-audio/t-rex-roar.mp3"
)
6. When only the text content such as <mpvoice, /mpvoice>, audio, etc. is included in the content, instead of closed and complete HTML tags, regular matching will not be triggered. as shown in Figure 1
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent/mpvoice>Listen to the T-Rex:audio controls src=\"/media/cc0-audio/t-rex-roar.mp3\">Your browser does not support theaudio element.
Array
(
[0] =>
[1] => class="js_editor_audio audio_iframe js_uneditable" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=%E4%B8%80%E4%B8%AA%E4%BA%BA%EF%BC%8C%E4%B9%9F%E6%8C%BA%E5%A5%BD&play_length=05:22" isaac2="1" low_size="612.81" source_size="612.8" high_size="2524.76" name="一个人,也挺好" play_length="322000" voice_encode_fileid="MzI1NjA0MDg2M18yNjUwNzYzNTcz" data-topic_id="1693506805106065417" data-topic_name="夜听精选" data-pluginname="insertaudio" style="margin-top: 50px; margin-right: 0px; margin-bottom: 0px; max-width: 100%;"
)
Array
(
[0] => Your browser does not support theaudio element.
[1] => controls src="/media/cc0-audio/t-rex-roar.mp3"
)
