duanfen7676 2015-01-22 11:34
浏览 5
已采纳

Preg_replace规则可以更有效地定位

I have some shortcodes that are dynamically generated in a post.

[shortcode 1][shortcode 2][shortcode 3] ... [shortcode 77]

I'm using the WP filter function to content_save_pre to run a preg_match on the content and remove all numbers from the shortcodes.

So:

[shortcode 1] becomes [shortcode]

...

[shortcode 77] becomes [shortcode]

This is what I use now

add_filter( 'content_save_pre' , 'preg_replace' , 10, 1);
funtion preg_replace ($content){
 $content = preg_replace('/shortcode .]/', 'shortcode]', $content);
 return $content;
}

My problem is that on some ocasions the double digit shortcodes do not get changed. This way seams to work (having 2 dots) but there surely is a better way to target the digits so that all of them get removed, regardless of home may there are.

$content = preg_replace('/shortcode ..]/', 'shortcode]', $content);
  • 写回答

1条回答 默认 最新

  • dongmei1988 2015-01-22 12:41
    关注

    Use this:

    $content = preg_replace('/shortcode \d+\]/', 'shortcode]', $content);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么