Page 1 of 1
Need some help with matches
Posted: Tue Dec 09, 2008 4:07 pm
by JKM
Hi there,
I wan't to check if $_GET['lol'] is beginning with ROFL* or not.
Code: Select all
if($_GET['lol'] starts with ROFL) {
$result = "LMAO";
}
else {
$result = "Get lost";
}
The question is how I can check this.
Re: Need some help with matches
Posted: Tue Dec 09, 2008 4:28 pm
by socket1
something like
Code: Select all
if(strpos($_GET['lol'], "ROFL") == 'int') {
echo "Found ROFL";
}
else
{
echo "No ROFL";
}
That code worked for me.
Re: Need some help with matches
Posted: Tue Dec 09, 2008 4:37 pm
by requinix
socket1 wrote:That code worked for me.
Uh... really?
Code: Select all
if (strncmp($_GET["lol"], "ROFL", 4) == 0) {
// starts with ROFL
} else {
// doesn't start with ROFL
}
If you use str[n]cmp it'll only look at the start of the search string and not scan the entire thing looking for a match.
Re: Need some help with matches
Posted: Tue Dec 09, 2008 4:43 pm
by socket1
Oh ok, thanks, didn't know that.