Seite 1 von 1

url prüfen (preg_match)

Verfasst: 08.06.2006 22:04
von Dave
Hi

Kann mir sagen wie ich mit preg_match prüfen kann ob eine url vollständig ist und mit .gz am ende endet?

MfG
Dave

Verfasst: 09.06.2006 11:54
von S2B
Einmal Code aus dem phpBB:

Code: Alles auswählen

	// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
	// xxxx can only be alpha characters.
	// yyyy is anything up to the first space, newline, comma, double quote or <
	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
Daraus lässt sich sowas bauen:

Code: Alles auswählen

	if (preg_match("#^([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+äöü]*)\.gz$#i", $string))
	{
		// passt
	}
(Code ist mal wieder ungetestet)