PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Tue Dec 09, 2008 4:07 pm
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.
socket1
Forum Commoner
Posts: 82 Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York
Post
by socket1 » Tue Dec 09, 2008 4:28 pm
something like
Code: Select all
if(strpos($_GET['lol'], "ROFL") == 'int') {
echo "Found ROFL";
}
else
{
echo "No ROFL";
}
That code worked for me.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Dec 09, 2008 4:37 pm
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.
socket1
Forum Commoner
Posts: 82 Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York
Post
by socket1 » Tue Dec 09, 2008 4:43 pm
Oh ok, thanks, didn't know that.