2012-04-02 18 views
0

So, I have a string of text:特定の<a href..certain.domain.com... with php preg_replace

string with a bunch of links but i need to simply get rid of these <a href="a.domain.com">Title</a> string with more links and text 

I need to get rid of everything from <a to a> where a.domain.com is present (its always the same domain) using PHP preg_replace.
It seems so simple but I can't figure this out >.< or find anywhere that explains regex :/

答えて

1

私は常に正規表現のために、このサイトのように:http://www.regular-expressions.info/ これは完全な答えではないが、私はちょうど<a [...]>[...]</a>と一致し、それは貪欲ではないことを確認しますので、あなたは<a [...]>の最初のoccuranceからすべてを引き裂くまで終わらないだろう最後まで</a>まで。いや、それだけで全部 サイトが良いカントーに見える削除する必要が

$rev= preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '', $_POST['rev']); 
0

If you're looking to keep what's inside the <a> tags, you can try the strip_tags()機能の置き換え。

あなたは正規表現を学ぶために、より複雑なもの、偉大なチュートリアルをしたい場合は、

$no_tags = preg_replace('#<a (.*?)>(.*?)</a>#', '', $text); 

ような何かをしようとしますが、あなたのタグはより複雑であれば、これが壊れることに注意することができますhttp://www.regular-expressions.info/

ですあなたが投稿した例。

+0

: は、これは別のフォーラムで推奨された、あなたはそれにもしてみてくださいを与えたいと思うかもしれません – King