(PHP)拒绝说明不包括所需要的标签
问题描述:
这是在描述太短怎么我的剧本目前发送错误:(PHP)拒绝说明不包括所需要的标签
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>
感谢您的帮助!
答
$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
}
这是英迪的解决方案的替代品。
答
答
我会使用一些正则表达式在这里,做一个负面的比赛
$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
它的工作!!:D感谢一个批次!!!!!! – funny 2011-06-06 11:46:20