View Full Version : Function help

06-20-2005, 03:48 PM
Ok a while back i asked for some help with functions and i though i got what i wanted done but for some strange reason it wont. What i want done is for right before the html in the script i am about to show is to have two functions. One of them looks for '/nickchange' at the beging of the post and if they have that it will change the cookie called 'name' to what is after '/nickchange'. The other one i want to look for '/me' at the beging write to the file with the html coding that is turn just the line it added purple. But the hard part is that i don't want it to add to the file '/nickchange bob' for example when it is done with the functions. Here is the script if there is any questions please ask me

<body align='center'>
<iframe src='filer.php' width='95%' height='85%' name="as">
<table width='95%'>
<td align='center' width='100%'>
<form action='chat.php' method='post' name='m'>
Message : <input name='msg' size=60><input type='submit' name='send' value='Send'>
$msg3 = $_POST["msg"];
$file = "file.txt";
$msg2 = $name . ":" . $msg3 . "\n";
$msg1 = str_replace("<", " &lt; ", "$msg2");
$msg = str_replace(">", " &gt; ", "$msg1");
$fp = fopen ($file, 'a+');
fwrite ($fp, $msg2);
fclose ($fp);
Echo "Please Input a Message";

06-20-2005, 09:54 PM
The simplest way to do such things:

$input = '/nickchange n00b';
if(substr($input, 0, 4) == '/me ')
print 'ME: ' . substr($input, 4);
elseif(substr($input, 0, 12) == '/nickchange ')
print 'I changed my nick to: ' . substr($input, 12);