我正在使用 qtranslate wordpress 插件以多种语言存储博客内容。现在我需要从 qtranslate 标签中提取内容。
$post_title = "<!--:en-->English text<!--:--><!--:it-->Italian text<!--:-->";
从该字符串返回文本和语言的 php 代码和正则表达式是什么?
非常感谢!
最佳答案
尝试这样的事情:
<?php
$post_title = "<!--:en-->English text<!--:--><!--:it-->Italian text<!--:-->";
$regexp = '/<\!--:(\w+?)-->([^<]+?)<\!--:-->/i';
if(preg_match_all($regexp, $post_title, $matches))
{
$titles = array();
$count = count($matches[0]);
for($i = 0; $i < $count; $i++)
{
$titles[$matches[1][$i]] = $matches[2][$i];
}
print_r($titles);
}
else
{
echo "No matches";
}
?>
打印:
Array
(
[en] => English text
[it] => Italian text
)
关于php - 从 Wordpress 标题返回文本的简单正则表达式 - qtranslate 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1853406/