douhandie6615
2013-09-20 03:09
浏览 41

Wordpress / PHP用div替换caption标签

I have this

[caption]<img />[/caption]

I have removed the caption tags usign this

$content = preg_replace("/\[.*?\]/", "", $content);

However, I want to replace it with div like this

<div><img></div>

What I am missing? Any help is appreciated.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhang3898 2013-09-20 04:00

    you could try like:

    $search_for = '/\[caption\](.*?)\[\/caption\]/is';
    $replace_with = '<div>$1</div>';
    $str = "[caption]<img />[/caption]";
    $replaced = preg_replace($search_for, $replace_with, $str);
    echo $replaced;
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题