2010-09-17 68 views
0

我正在使用我的博客的聯繫頁面插件。使用此代碼的短代碼是 [my-shortcode]。 是否有反正只過濾來自內容的簡碼。 如: Test post [my-shortcode] Demo widget。在這裏我需要過濾只有shortcode.Thank你僅從帖子中過濾短代碼

+0

看看在這個問題的答案,問勉強幾個小時前http://stackoverflow.com/questions/3734519/seach-inside-a -string也提取信息[和] – 2010-09-17 11:10:03

回答

0

您可以使用正則表達式來得到一個字符串中括號內的值,像這樣。

if(preg_match_all('/\[(.*?)\]/',$_POST['my_key'],$matches)) 
{ 
    foreach($matches as $match) 
    { 
     if($match[1] == 'my-short-code') 
     { 
      //Do whetever 
      break 2; 
     } 
    } 
} 

注:match[1]可能match[0]

+0

非常感謝你 – 2010-09-17 11:23:28