Jump to content

Recommended Posts

See if this is something like you are wanting. RegEx Library

<?php
/*regEx pattern from Regular Expression Library */
$pat = '~^(?=[^&])(??<scheme>[^:/?#]+)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?~';
/* array of sites, so that you can see the different returns */
$sites[] = 'http://www.google.com';
$sites[] = 'http://google.com';
$sites[] = 'http://google.com/dfgjndfkgjndfg';
$sites[] = 'http://www.google.com/dijgndfgn';

/* looping through the sites array */
foreach($sites as $str) {
preg_match_all($pat,$str,$match); //match each site against the expression. 
$parts = explode('.',$match['authority'][0]); //grab the authority and split it on any period (.).

foreach($parts as $value) {//cycle through the parts array created by explode().
	if(strlen($value) < 4) { continue; } //if the value is less than 4 (minimum web address), then skip the next step.
	 echo 'Website: ' . $value . '<br />'; //if it is greater than or equal to 4 chars. then echo it to the screen.
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/239274-strip-url/#findComment-1229363
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.