如何从这个旋转语法代码中删除星号



这是我的代码,它是一个文本微调器(同义词)

public function fetchContent($keyword)
{
    $customContent = $this->getOption('custom_content_text');
    $this->_setHttpStatusCode(200);
    if (!$customContent)
    {
        $this->_setContentStatus(self::CONTENT_STATUS_NO_RESULTS);
        return false;
    }
    if (preg_match_all('/({*)(.*?)(*})/', $customContent, $result))
    {
        if (is_array($result[0]))
        {
            foreach ($result[0] as $index => $group_string)
            {
                //replace the first or next pattern match with a replaceable token
                $customContent = preg_replace('/({*)(.*?)(*})/', '{#'.$index.'#}', $customContent, 1);
                $words = explode('|', $result[2][$index]);
                //clean and trim all words
                $finalPhrase = array();
                foreach ($words as $word)
                {
                    if (preg_match('/S/', $word))
                    {
                        $word = preg_replace('/{%keyword%}/i', $keyword, $word);
                        $finalPhrase[] = trim($word);
                    }
                }
                $finalPhrase = $finalPhrase[rand(0, count($finalPhrase) - 1)];
                //now inject it back to where the token was
                $customContent = str_ireplace('{#' . $index . '#}', $finalPhrase,    $customContent);
            }
            $this->_setContentStatus(self::CONTENT_STATUS_PASSED);
        }
    }
    return $customContent;
}
}

有一个regex请求像这样的括号

   {*spin1|spin2|spin3*}

这是上面的代码段中的正则表达式

   if (preg_match_all('/({*)(.*?)(*})/', $customContent, $result))
   $customContent = preg_replace('/({*)(.*?)(*})/', '{#'.$index.'#}', $customContent, 1);

我想删除*to格式,只允许{spin1|spin2|spin3}与大多数微调器更兼容

我尝试了一些我在网上找到的正则表达式我试图从两个正则表达式中删除*,但没有结果

非常感谢您的帮助

删除*而不仅仅是*–Lucas Trzesniewski

最新更新