2012-04-11 57 views
-2

可能重複:
RegEx match open tags except XHTML self-contained tags如何preg_replace一個HTML(A)標籤?

這是一個標籤代碼:

<a href="http://google.com/">Google</a> 

如何使用的preg_replace函數提前加http://google.com/

另一個URL例如:

不更改:

<a href="http://google.com/">Google</a> 

更改後:

<a href="http://myurls.com/index.php?to=http://google.com/">Google</a> 

看到有?? !!

我原來的URL

現在

前加入http://myurls.com/index.php?to= ,,

它是如何通過的preg_replace做了什麼?

感謝名單

+4

[不要溫和地走進那個良夜,風靡一時..怒斥光明的消逝(HTTP://www.bigeye。 com/donotgo.htm)..然後使用適當的DOM解析器。 – 2012-04-12 19:33:58

回答

0

試試這個:

$toStr = preg_replace("/<a\shref=\"http:\/\//","${1}http://myurls.com/index.php?to=",$fromStr);