从标题中删除一些文字

时间:2016-09-12 17:27:39

标签: php wordpress

我需要自动从标题中删除一些文字。例如,我的帖子标题来自XML Feed并显示:"Nashville Fried Chicken Sandwich [800x800]"。我需要从标题中删除"[800x800]",所以我需要在PHP中执行:

$post [‘post_title’] – title; 
//exclude all the :[]

1 个答案:

答案 0 :(得分:0)

preg_replace会做你的工作!

这是一个例子

$string = "ABC [Test1]";
echo preg_replace("/\[[^)]+\]/","",$string); // Outputs 'ABC '

所以这preg_replace("/\[[^)]+\]/","",$string);会做你期望的事情!

相关问题