Skip to content

Commit

Permalink
Method to generate a site id from a url
Browse files Browse the repository at this point in the history
  • Loading branch information
omahm committed Dec 16, 2022
1 parent 714dfb5 commit df3ed39
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ public static function createApplicationId($name) {
return strtolower(str_replace(' ', '_', $name));
}

/**
* Create a machine safe site ID.
*
* @param string $url
* Url to create a site ID for.
*
* @return string
* Machine safe site ID.
*/
public static function createSiteId($url) {
$url = strtolower(str_replace('-', '', $url));

// Strip http, www and domain to leave site name.
preg_match_all('/(http:\/\/)*(?:www\.)?([a-z0-9\-]+)(?:\.[a-z\.]+[\/]?).*/', $url, $matches, PREG_SET_ORDER, 0);
return $matches[0][2];
}

}

0 comments on commit df3ed39

Please sign in to comment.