简单的正则表达式从Wordpress标题返回文本 - qtranslate插件

Kel*_*vin 3 php regex wordpress-plugin qtranslate

我使用qtranslate wordpress插件以多种语言存储博客内容.现在我需要从qtranslate标签中提取内容.

$post_title  = "<!--:en-->English text<!--:--><!--:it-->Italian text<!--:-->";
Run Code Online (Sandbox Code Playgroud)

什么是PHP代码和正则表达式从这个字符串返回文本和语言?

非常感谢!

Atl*_*tli 6

尝试类似的东西:

<?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";
}
?>
Run Code Online (Sandbox Code Playgroud)

打印:

Array
(
    [en] => English text
    [it] => Italian text
)
Run Code Online (Sandbox Code Playgroud)