リニューアルしました。
このページは、2005年8月後半から2010年12月までのアーカイブです。
2005年8月後半から2010年12月までのアーカイブトップへ

現在のトップページはこちら

MT エントリー内の特定の単語を削除・置き換え

Nagi
   2010.03.05 15:42

MTの記事を書くプラグインを入れたいという要望があったので、FCKeditorを入れたところ、本文中に複数の画像を入れて位置指定するとゴミが入るようになった。
(いろいろいじってるから、プラグインのせいではないかもしれない・・・。
あと、画像のURLは省略してますよ。これはサンプルソース。)

<span style="display: inline" class="mt-enclosure mt-enclosure-image"><img style="margin: 0px 0px 20px 20px; float: right" class="mt-image-right" alt="gazou02.gif" width="200" height="150" src="thumb-200x150-104.gif" /></span>
<span style="display: inline" class="mt-enclosure mt-enclosure-image">&nbsp;</span>
<span style="display: inline" class="mt-enclosure mt-enclosure-image"><img style="margin: 0px 20px 20px 0px; float: left" class="mt-image-left" alt="gazou01.gif" width="200" height="150" src="thumb-200x150-100.gif" /></span>

真ん中の
<span style="display: inline" class="mt-enclosure mt-enclosure-image">&nbsp;</span>
これがあるために、左右に並べたい画像が段違いになってしまう。

本文から特定の単語・文章を削除するようなことはできないのか調べてみた。

正規表現の置き換えがregex_replaceでできるそうなので、 空白スペースの「&nbsp;」をターゲットに

<mt:entrybody regex_replace="/&nbsp;/",""> これで解決。

2枚以上画像があると空白もふえていくようなので、置換演算子のgを指定。

<mt:entrybody regex_replace="/&nbsp;/g",""> これで完璧。

今回やらなかったけれど、もしかしたら<span> ~</span>自体置き換えできるかも?

アーカイブ

Powered by Movable Type 4.28-ja