2017-03-18 57 views
0

鏈接我創建了錨標籤的內容我想要得到的鏈接如何從內容在PHP

形式帖子內容後。存儲在數據庫中的數據如下: -

<a href="https://www.manresa-sj.com/wp-content/uploads/2017/02/PhotoOfSteve.png">all data is here for you</a> 


WP_Post Object 
(

    [post_content] => all data is here for you 

) 

我從喜歡https://www.manresa-sj.com/wp-content/uploads/2017/02/PhotoOfSteve.png

的POST_CONTENT鏈接想這可能嗎?

回答

1

如果你的意思是你想從文本中提取圖像鏈接。 使用正則表達式。

$string = '<a href="https://www.manresa-sj.com/wp-content/uploads/2017/02/PhotoOfSteve.png">all data is here for you</a>'; 

$pattern = '~(http.*\.)(jpe?g|png|[tg]iff?|svg)~i'; 

$m = preg_match_all($pattern,$string,$matches); 

print_r($matches[0]);