Welcome Guest! To access all forums & features, please register an account or sign-in. → Why register?



Regex help... maybe?


3 replies to this topic - - - - -

#1 +McCordRm

    http://richardmccord.com

  • 2,932 posts
  • Joined: 06-July 06
  • Location: Dallas, TX

Posted 03 August 2012 - 20:08

So I want to create a header which changes based on the Domain it's located at.
For example:

Site 1: http://www.signsofmadness.com
Site 2: http://www.signsoflove.org
Site 3: http://www.signsofaddiction.com


If I upload the index.html page to all three sites, the title of the site should read across the top:

Site 1: Signs of Madness
Site 2: Signs of Love
Site 3: Signs of Addiction


Am I making sense?


#2 +Phouchg

    Blackheart

  • 3,775 posts
  • Joined: 28-March 11
  • Location: Krikkit
  • OS: GrumpyOS 6.1.7601 x64

Posted 04 August 2012 - 01:06

Why bother? Substring from position of signsof + 8 to next . from there in your prefered scripting language could do.

#3 +chorpeac

    NeoRequest Engineer

  • 6,915 posts
  • Joined: 21-March 02
  • Location: Northern Virginia
  • OS: Windows, Windows RT, Windows Phone, & iOS

Posted 04 August 2012 - 01:20

http://stackoverflow...domain-from-url

Look at the second to last and last posts.

http://([^/]+).*

Or
'/http:\/\/([^\/]+)\//i'

#4 CrispCreations

    Neowinian³

  • 468 posts
  • Joined: 19-April 04
  • Location: North West, UK

Posted 04 August 2012 - 09:41

You don't really need a regex for this, the $_SERVER global in php has an HTTP_HOST value you can test against


switch ($_SERVER["HTTP_HOST"]) {
	case 'www.example.com':
		// do stuff for www.example.com
		break;
	case 'www.example1.com':
		// do stuff for www.example1.com
		break;
	// add more cases as needed
}