-1
4

1 に答える 1

1

strip_tags()許可されているものとして指定したタグを除いて、文字列からすべての html タグを削除します。

編集:以下のコメントに従って;

ブラウザがタグを解析せずに、HTML タグを含む文字列をテキストとして表示するには、htmlspecialchars()またはを使用する必要がありますhtmlentities()。次に、@mention をリンクに置き換えるには、正規表現とpreg_replace().

これがあなたが何を求めているか(私が思うに)の例です:-

<?php

$string = "Some text with some <span>HTML tags in it</span> and a @mention to someone";

// Turn special characters into html entities
$new_string = htmlspecialchars($string);

// Replace @mention with a link
$output = preg_replace("/@(\w+)/",'<a href="http://www.example.com/profiles/$1">$1</a>',$new_string);

// Will produce 'Some text with some &lt;span&gt;HTML tags in it&lt;/span&gt; and a <a href="http://www.example.com/profiles/mention">mention</a> to someone'
echo $output;

?>
于 2012-04-06T14:10:35.163 に答える