PHP: preg_match 限制表单文本区域中的锚文本
PHP: preg_match limit anchor text in form textarea
我正在尝试将文本区域中的锚文本数量限制为 1。
经过几周的研究,我无法使用此代码做到这一点
if(preg_match('/.*http:\//', $content->description) > 1) {
else 'You can not submit Anchor text more than one times';
}
<textarea>
<a href="https://example.com/">Anchor text 1</a>
<a href="http://example2.com/">Anchor text 2</a>
<a href="https://www.example3.com/">Anchor text 3</a>
<a href="http://www.example4.com/">Anchor text 4</a>
Not Anchor text http://www.example.com/
</textarea>
如何使用 "preg_match" 限制在表单文本区域中提交 HTML 标签 <a>
?
使用 DOMDocument:
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($content->description);
if ( $dom->getElementsByTagName('a')->length > 1 ) {
...
我正在尝试将文本区域中的锚文本数量限制为 1。
经过几周的研究,我无法使用此代码做到这一点
if(preg_match('/.*http:\//', $content->description) > 1) {
else 'You can not submit Anchor text more than one times';
}
<textarea>
<a href="https://example.com/">Anchor text 1</a>
<a href="http://example2.com/">Anchor text 2</a>
<a href="https://www.example3.com/">Anchor text 3</a>
<a href="http://www.example4.com/">Anchor text 4</a>
Not Anchor text http://www.example.com/
</textarea>
如何使用 "preg_match" 限制在表单文本区域中提交 HTML 标签 <a>
?
使用 DOMDocument:
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($content->description);
if ( $dom->getElementsByTagName('a')->length > 1 ) {
...