2011-06-06 71 views
0

这是在描述太短怎么我的剧本目前发送错误:(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> 

感谢您的帮助!

回答

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 
} 

这是英迪的解决方案的替代品。

+0

它的工作!!:D感谢一个批次!!!!!! – funny 2011-06-06 11:46:20

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

+0

Upvoted,但您的常量('minStoryLength')实际上应该用大写字母区分其他变量。 – 2011-06-06 11:30:36

+0

@rudi_visser你的意思是“我的”常量或提问者的?我只是使用提供的代码并添加了我的解决方案。 – aorcsik 2011-06-06 11:36:59

+0

我试过这样但有些不起作用: – funny 2011-06-06 11:37:59