URIが文字列内にあるかどうかを検出し、適切にサニタイズして、適切なアンカータグを付けて出力したいと思います。
つまり、ユーザーは次のように入力します。
Check out our profile on facebook!
https://facebook.com/ourprofile
and our twitter!
twitter.com/#!/ourprofile
and email us!
ourprofile@stack.com
文字列にURIがあることを確認し、安全でない文字をサニタイズし、安全なアンカーを適切に出力する方法はありますか?
したがって、出力は次のようになります。
Check out our profile on facebook!
<a href="https://www.facebook.com/ourprofile">https://www.facebook.com/ourprofile</a>
and our twitter!
<a href="http://www.twitter.com/#!/ourprofile">twitter.com/#!/ourprofile</a>
and email us!
<a href="mailto:ourprofile@stack.com">ourprofile@stack.com</a>
私が考えていたアイデアは、安全でない文字を削除するために使用していてpreg_match
簡単preg_replace
でしたが、これは失敗し、私はただ輪になって、これをどこから始めればよいのか本当にわかりません。そのようなブラックリストのアプローチは適切ではないことがほぼ確実です。または安全です。