Re: Checking for a string.

From: Date: Tue, 29 Oct 2002 19:30:11 +0000
Subject: Re: Checking for a string.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-121927@lists.php.net to get a copy of this message
http://www.php.net/manual/en/function.preg-match.php Wrong syntax, and more code than needed. Your code would always resolve true (if ($matches[0] = "http")). Doing that sets the value of $matches[0] to "http". Equality is ==. RTFM. If all you want to know is if the URL contains a "http", then... if ( preg_match ( "/http/i", $path ) ) { $action = "this action"; } else { $action = "that action"; } If you want to know if the URL starts with a "http", then... if ( preg_match ( "/^http/i", $path ) ) { $action = "this action"; } else { $action = "that action"; } ed@home.homes2see.com wrote:
Seems to work but I'm getting a Warning Message: Delimiter must not be alphanumeric or backslash Here's the code: $path = "http://somehost.somedomain.com"; preg_match ("http", $path, $matches); if ($matches[0] = "http") { $action = "this action"; } else { $action = "that action"; } Thanks much, Ed On Tue, 29 Oct 2002, John Nichel wrote:
preg_match() ed@home.homes2see.com wrote:
I'm currently writting a redirect script for my site which will transfer someone to either a external link or a directory on my server. In order to do this I need to use a directive that either contains the directory path or a URL. How do I check the contents of a string to see if it contains "http"? Thanks, Ed
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#121927) next »