-1

I have this text that returns from a wordpress plugin's shortcode:

"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>"

Out of all this text, how can I only keep the url "http://mywebsite.com/wordpress/wp-login.php?action=register&ref=1"?

HamZa
  • 14,671
  • 11
  • 54
  • 75
Kokas
  • 131
  • 1
  • 11

1 Answers1

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];
Ali Alnoaimi
  • 2,278
  • 2
  • 21
  • 31