LoginSignup
1
1

More than 5 years have passed since last update.

SmartyでHTMLタグと改行コードをまとめて削除する方法

Posted at

EC-CUBE2.12系でのこと。
商品詳細ページのコメント欄の情報をJSONデータに渡す時にHTMLや改行コードが混ざっていたので、Smartyのテンプレート側で削除して渡したい時に記述した内容のメモ。

<!--{$arrProduct.main_comment|nl2br|strip:""|strip_tags:false|escape}-->

$arrProduct.main_commentがコメントの情報。
それをパイプでパラメータを渡して順番に前から処理。

  1. nl2brで改行コードを<br>タグに変換
  2. 空白・改行・タブを置換するstrip修飾子で空白に置換
  3. strip_tagsでHTMMLタグを除去
  4. escapeでタグの無効化を念の為

これで削除できました \(^o^)/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1