kneuf
08-06-2004, 10:42 AM
hi all, i'm not a regular expression junkie so I don't know how to go about this. actually, i know pretty much nothing when it comes to this... so i come here in hopes that a fellow whter will know the answer i seek! ok, here what i am trying to do (probably very simple): search a string for a domain, say, mydomain.com, and display an error like: error you are trying to access a restricted site, please enter another. thanks :)
Not sure exactly what you mean, what sort of string are you trying to search? can you give more of an example of the situation?
The most basic example i can think of is:
$x = 0;
$string = 'welcome to mydomain.com';
if(eregi('mydomain.com', $string)) $x = 1;
In this case $x would return "1" don't know if that helps.
kneuf
08-06-2004, 04:13 PM
thx, thats sort of it. what i need is something that will display an error (just set a variable would be fine here) if the entered string contains the url: mydomain.com and any variant (by this i mean http://, www, http://wwww., etc.) hope it helps clear this up
[update]i must be tired but ur example might work!
JimPanse
08-09-2004, 04:26 AM
you shoulndt use regulare expressions for this easy kind of string-compare. For performance reasons i would use
strstr() or stristr() if you just would like to know, if the domainname is a part of given string.
kinda
if(!stristr($stringtosearch, $search)){
echo "$search is not a part of $stringtosearch";
exit;
}
kneuf
08-10-2004, 02:44 PM
thanks jimpanse, it works!