Results 1 to 9 of 9

Thread: creating a word filter

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    creating a word filter

    I cant seem to make it so that when it searches for a word... it doesnt care about the 'caSe'.


    I looked on PHP.net cuz i remembed seeing sumtin about it in an example. but....


    Oh and google wasnt my friend when i searched for it.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2
    Junior Member
    Join Date
    Oct 2005
    Posts
    26

    Re: creating a word filter

    Code:
    $newphrase = str_replace($old, $new, $text);
    For example, If you wanted to replace all commas with spaces...
    Code:
    $text = "Hey,this,is,an,example";
    $text = str_replace(",", " ", $text);
    //$text would equal "Hey this is an example"
    I hope this is what you needed


    Bear

  3. #3

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: creating a word filter

    thanks for the reply. But thats not what i meant.
    Im sorry for "implying my question" in a "vague" way. I do that sumtimes.

    If you read my first line carefully you'll understand my question.
    If Not Read on.

    I cant seem to make it "not Care" about CaSe.


    As in. If theres a word like Homo.(Example). It doesnt matter what the case of the word is. it will still be replaced.

    Example:

    Homo
    HoMo
    HOMO
    hOmO
    hOMO
    etc...etc.. etc...
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Don't Rate my posts.

  5. #5

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: creating a word filter

    how bout for those whos host dont use PHP 5?
    lol

    cuz str_ireplace(); doesnt even "change color" in the editor.
    nor does it work when run.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  6. #6
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: creating a word filter

    Crikey, how can that not exist in PHP 4?

    PHP Code:
    $string 'The quick brown fox jumped over the lazy dog.';
    $patterns[0] = '/(?i)Quick/';
    $patterns[1] = '/(?i)Brown/';
    $patterns[2] = '/fox/';
    $replacements[2] = 'bear';
    $replacements[1] = 'black';
    $replacements[0] = 'slow';
    echo 
    preg_replace($patterns$replacements$string); 
    Just a modified example from PHP.net, http://au2.php.net/preg_replace

    This is the other way that I've found (haven't searched hard though, so perhaps someone has a better way? )

    The patterns are the things your searching for, replacements, whats to replace it with, and the (?i) makes it case insensitive, so it needs to be included.
    Don't Rate my posts.

  7. #7

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: creating a word filter

    koo. Thanks.
    Ill try it out.

    EDIT - Worked out exactly how i wanted it to.
    Last edited by PlaGuE; Dec 6th, 2005 at 01:41 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  8. #8
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Re: creating a word filter

    ==============================
    = str_replace
    ==============================

    Compability :
    ==========

    works with PHP3, PHP4 and PHP5
    Linux and Widnows

    Code :
    ======

    <?php

    // Provides: You should eat pizza, beer, and ice cream every day
    $phrase = "You should eat fruits, vegetables, and fiber every day.";
    $healthy = array("fruits", "vegetables", "fiber");
    $yummy = array("pizza", "beer", "ice cream");

    $newphrase = str_replace($healthy, $yummy, $phrase);

    ?>

    Descriptions :
    ==========

    It replaces word like as given in code above.

    http://ca3.php.net/manual/en/function.str-replace.php
    Muhammad Furqan Attari.

  9. #9
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: creating a word filter

    But str_replace is case sensitive, which isn't what hes after.
    Don't Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width