PDA

View Full Version : Best way to do this?



Moh
11-09-2008, 08:12 PM
What would be the best way to do the following:
In a shoutbox, you type in "/ban Jack", whats the best way of checking if:
/ban is at the beginning of the string

So if someone types in "the command is /ban jack" it wont do anything?

Invent
11-09-2008, 08:39 PM
<?php

$string = '/ban lol';

if( preg_match( '/^\/ban (.*)$/i', $string, $match ) )
{

$username = $match[ 1 ];
echo $username;

}

?>

Moh
12-09-2008, 12:53 AM
<?php

$string = '/ban lol';

if( preg_match( '/^\/ban (.*)$/i', $string, $match ) )
{

$username = $match[ 1 ];
echo $username;

}

?>

Thank you Simon :)

Want to hide these adverts? Register an account for free!