<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.strip-tags.php',
    1 => 'strip_tags',
    2 => '文字列から HTML および PHP タグを取り除く',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String 関数',
  ),
  'prev' => 
  array (
    0 => 'function.strcspn.php',
    1 => 'strcspn',
  ),
  'next' => 
  array (
    0 => 'function.stripcslashes.php',
    1 => 'stripcslashes',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/strings/functions/strip-tags.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strip-tags" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strip_tags</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strip_tags</span> &mdash; <span class="dc-title">文字列から HTML および PHP タグを取り除く</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strip-tags-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strip_tags</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$allowed_tags</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   この関数は、指定した文字列 (<code class="parameter">string</code>)
   から全ての NULL バイトと HTML および PHP タグを取り除きます。
   この関数は、<span class="function"><a href="function.fgetss.php" class="function">fgetss()</a></span> 関数と同じタグ除去アルゴリズムを使用します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strip-tags-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       入力文字列。
      </p>
     </dd>
    
    
     <dt><code class="parameter">allowed_tags</code></dt>
     <dd>
      <p class="para">
       オプションの2番目の引数により、取り除かないタグを指定できます。
       これは <span class="type"><a href="language.types.string.php" class="type string">string</a></span> で指定できますが、PHP 7.4.0 以降では <span class="type"><a href="language.types.array.php" class="type array">array</a></span> でも指定可能です。
       この引数のフォーマットについては、以下の例を参照ください。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        HTML コメントや PHP タグも削除されるようになりました。この機能はハードコードされており、
        <code class="parameter">allowed_tags</code> で変更することはできません。
       </p>
      </p></blockquote>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        <code class="parameter">allowed_tags</code> で使えるのは自己終了型でない XHTML タグだけです。
        自己終了型の XHTML タグは無視されます。たとえば、
        <code class="literal">&lt;br&gt;</code> と
        <code class="literal">&lt;br/&gt;</code> の両方を許可したい場合は、以下のようにしなければいけません。
       </p>
       <div class="informalexample">
        <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #DD0000">'&lt;br&gt;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
        </div>

       </div>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strip-tags-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   タグを除去した文字列を返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strip-tags-changelog">
  <h3 class="title">変更履歴</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>バージョン</th>
       <th>説明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">allowed_tags</code> は、nullable になりました。
       </td>
      </tr>

      <tr>
       <td>7.4.0</td>
       <td>
        <code class="parameter">allowed_tags</code> は、<span class="type"><a href="language.types.array.php" class="type array">array</a></span> も受け入れるようになりました。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strip-tags-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>strip_tags()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$text </span><span style="color: #007700">= </span><span style="color: #DD0000">'&lt;p&gt;Test paragraph.&lt;/p&gt;&lt;!-- Comment --&gt; &lt;a href="#fragment"&gt;Other text&lt;/a&gt;'</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// &lt;p&gt; と &lt;a&gt; は許可します<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">, </span><span style="color: #DD0000">'&lt;p&gt;&lt;a&gt;'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// PHP 7.4.0 以降では、上の行は以下のように書けます:<br />// echo strip_tags($text, ['p', 'a']);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>上の例の出力は以下となります。</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Test paragraph. Other text
&lt;p&gt;Test paragraph.&lt;/p&gt; &lt;a href=&quot;#fragment&quot;&gt;Other text&lt;/a&gt;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strip-tags-notes">
  <h3 class="title">注意</h3>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    XSS攻撃を防ぐ目的で、この関数を使うべきではありません。
    <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span> のような、より適切な関数、
    もしくは、出力のコンテキストによっては他の手段を使うようにしてください。
   </p>
  </div>  
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    <span class="function"><strong>strip_tags()</strong></span> は HTML の検証を行わないため、
    不完全または壊れたタグにより予想以上に多くのテキスト/データが削除される可能性があります。
   </p>
  </div>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    この関数は、<code class="parameter">allowed_tags</code> で許可した全てのタグの属性を修正しません。
    これには、<code class="literal">style</code>
    および <code class="literal">onmouseover</code>属性が含まれており、
    悪意のあるユーザーが他のユーザーに見せるようなテキストを投稿する際に危険な行為を行う可能性があります。
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    HTML の中にあるタグの中で 1023 バイトより長い名前のものがあれば、
    たとえ <code class="parameter">allowed_tags</code>
    パラメータに指定していたとしても無効なタグと見なされます。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strip-tags-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.htmlspecialchars.php" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - 特殊文字を HTML エンティティに変換する</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>