我有这个文字从wordpress插件的短代码返回:
"Your plain link is: http://mywebsite.com/wordpress/wp-login.php?action=register&ref=1<br /><p> <small><em>Powered by <a href="http://markessence.com/blog/demo/wp-referral/" title="WordPress Referral Plugin" target="_blank" rel="external"> WordPress Referral Plugin</em></small></p>"
在所有这些文字中,我怎样才能保留网址"http://mywebsite.com/wordpress/wp-login.php?action=register&ref=1"
?
答案 0 :(得分:1)
$str = 'Your plain link is: http://mywebsite.com/wordpress/wp-login.php?action=register&ref=1<br /><p> <small><em>Powered by <a href="http://markessence.com/blog/demo/wp-referral/" title="WordPress Referral Plugin" target="_blank" rel="external"> WordPress Referral Plugin</em></small></p>';
$pattern = '#(www\.|https?:\/\/){?}[a-zA-Z0-9]{2,254}\.[a-zA-Z0-9]{2,4}(\S*)#i';
preg_match_all($pattern, $str, $matches, PREG_PATTERN_ORDER);
$url = $matches[0];