2
我需要去除由joomla/K2
创建的元描述中的一些花括号。Joomla:K2 - 如何使用preg_replace去除元描述中的花括号
我发现了两个php
解决方案,以剥离不需要的大括号:
$description = preg_replace('/{.+?}/', '', $description);
和
$metaDescItem = str_replace('/{.+?}/', '', $metaDescItem);
有其控制我的应用程序的内容不同的大括号:
{123456789}, {123456789,123456789}, {URL}, {}
最好的解决方案n会去掉元描述输出中的任何大括号。
我是新来的PHP,我不知道哪个功能是正确的。
接下来的问题是,我不知道在哪里插入功能K2的php
文件。
我想我找到了合适的php
文件,它生成了元描述。
下面是引自/components/com_k2/views/item/view.html.php
:
// Set metadata
if ($item->metadesc)
{
$document->setDescription((K2_JVERSION == '15') ? htmlspecialchars($item->metadesc, ENT_QUOTES, 'UTF-8') : $item->metadesc);
}
else
{
$metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext.' '.$item->fulltext);
$metaDescItem = strip_tags($metaDescItem);
$metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
$document->setDescription(K2_JVERSION == '15' ? $metaDescItem : html_entity_decode($metaDescItem));
}
谢谢!它的工作原理,但只剥去大括号。我们也想去掉大括号的内部。有什么建议么? Thx – Christoph 2015-02-09 20:05:39
啊,我没有得到它,我会改变我的答案。 – 2015-02-09 20:18:56
非常感谢您的支持。有用!!! – Christoph 2015-02-09 20:50:54