Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Function help

  1. #1
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function help

    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
    Code:
    <html>
    <head>
    </head>
    <body align='center'>
    <center>
    <iframe src='filer.php' width='95%' height='85%' name="as">
    </iframe>
    <br>
    <table width='95%'>
    <tr>
    <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'>
    <br>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    $name=$_COOKIE["name"];
    if(isset($_POST["msg"]))
    {
    $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";
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The simplest way to do such things:
    PHP Code:
    <?php
    $input 
    '/nickchange n00b';
    if(
    substr($input04) == '/me ')
    {
        print 
    'ME: ' substr($input4);
    }
    elseif(
    substr($input012) == '/nickchange ')
    {
        print 
    'I changed my nick to: ' substr($input12);
    }
    ?>
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •