-1

我有从 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>"

在所有这些文本中,我怎样才能只保留 url "http://mywebsite.com/wordpress/wp-login.php?action=register&ref=1"

4

1 回答 1

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];
于 2013-08-28T19:15:45.930 回答