这是我的脚本当前描述太短时发送错误的方式:
if(strlen($linkres->content) = minStoryLength ) { // if description is too short
$main_smarty->assign('submit_error', 'incomplete');
$main_smarty->display($the_template . '/submit_errors.tpl');
$error = true;
}
当描述中不包含至少一个标记/单词时,我想发送相同的错误消息:
<img><youtube><googlevideo><xoinks><break><vimeo><revver><myspace>
<veoh><wmv><dailymotion><ifilm><metacafe><tubeley><guba>
感谢您的帮助!
答案 0 :(得分:2)
我会在这里使用一些正则表达式进行否定匹配
$tags = array("img", "youtube", "googlevideo", "xoinks", "break", "vimeo", "revver", "myspace", "veoh", "wmv", "dailymotion", "ifilm", "metacafe", "tubeley", "guba");
if ((strlen($linkres->content) < minStoryLength) // if description is too short
|| (!preg_match("'[<](".implode("|",$tags).")[^>]*[>]'is",$linkres->content)))
// or it does not contain any of the above
{
$main_smarty->assign('submit_error', 'incomplete');
$main_smarty->display($the_template . '/submit_errors.tpl');
$error = true;
}
编辑:做了一点修改
EDIT2:我的preg_match
答案 1 :(得分:0)
答案 2 :(得分:0)
$tags = array('img','youtube','googlevideo','xoinks','break','vimeo','revver','myspace','veoh','wmv','dailymotion','ifilm','metacafe','tubeley','guba');
$contains = false;
foreach($tags as $check)
{
if(preg_match("/<".$check.">/", $linkres->content))
{
$contains = true;
}
}
if(!$contains)
{
// here goes your error
}
这是inti解决方案的替代方案。