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代码和正则表达式从这个字符串返回文本和语言?
非常感谢!
尝试类似的东西:
<?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)
| 归档时间: |
|
| 查看次数: |
2619 次 |
| 最近记录: |