サポート » その他 » 投稿文から画像(img)タグのみを削除する。

  • 解決済 chabin

    (@chabin)


    はじめて、質問をさせていただきます。
    同じようなトピックがあったら申し訳ありません。

    親ページに子ページの本文を表示させています。

    本文に使われている、htmlタグを削除する方法は分かったのですが、
    改行などのコードは、残して表示するにはどうしたらいいでしょうか?

    <?php
    if ( $post->post_parent == 0 ) {
    //子ページの情報を取得
    $child_posts = get_posts( 'numberposts=-1&order=ASC&orderby=post_title&post_type=page&post_parent=' . $post->ID );
    if ( $child_posts ) {
    foreach ( $child_posts as $child ) {
    //子ページのタイトル
    $c_title = apply_filters( 'the_title', $child->post_title );
    //子ページのパーマリンク
    $c_permalink = apply_filters( 'the_permalink', $child->post_title );
    //子ページの本文
    $c_content = get_extended( $child->post_content);
    $c_content = apply_filters('the_content', $c_content['main'] );
    //htmlのタグ外し
    $c_content = strip_tags($c_content);
    ?>

    アドバイスを宜しくお願い致します。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • strip_tagsの2番目の引数が取り除かないタグの設定になりますよ。

    詳しくはマニュアル参照してください。
    http://jp2.php.net/manual/ja/function.strip-tags.php

    トピック投稿者 chabin

    (@chabin)

    kouenさん

    有難うございました。
    無事解決いたしました。

    マニュアルにあったのですね。
    勉強になりました。

    分からないことがあったら、マニュアルを見直すというのも
    頭に入れておきます!

    // 修正前
    $c_content = strip_tags($c_content);
    
    // 修正後
    $c_content = strip_tags($c_content,'<p><a><br>');

    ご指導有難うございました。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「投稿文から画像(img)タグのみを削除する。」には新たに返信することはできません。