Jump to content

strip url


seany123

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.