Simple Regular Expression to return text from Wordpress title - qtranslate plugin

三世轮回 提交于 2019-12-06 02:15:31

Try something like:

<?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";
}
?>

Prints:

Array
(
    [en] => English text
    [it] => Italian text
)
jphase

These are all brilliant examples. However, I recently discovered qTranslate has their own function available:

qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_title);

Which will grab the current language and fail over to the default.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!