Activity Stream
48,167 MEMBERS
61176 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18
  1.     
    #11
    Respected Developer
    How about

    PHP Code: 
    <?php

    function clean($txt)
    {
        
    // remove everything that is not a word, _, -, whitespace or a number
        
    $result preg_replace('/[^\w\d\s\-]+/'''$txt);
        
    // replace numbers with a space
        
    $result preg_replace('/\d+/'' '$result);
        
    // remove words <= 3 chars
        
    $result preg_replace('/\b\w{1,3}\b/'''$result);
        
    // trim spaces
        
    $result preg_replace('/[ ]{2,}/'' '$result);
        
    // trim spaces at the end or beginning of lines
        
    $result preg_replace('/[ ]*(\r{0,1}\n)[ ]*/''$1'$result);
        
        return 
    $result;
    }

    ?>
    Grrr PHP

  2.   Sponsored Links

  3.     
    #12
    Respected Developer
    Website's:
    wrzc.org
    Quote Originally Posted by Hyperz View Post
    How about

    PHP Code: 
        // trim whitespace at the end or beginning of lines
        
    $result preg_replace('/[ ]*(\r{0,1}\n)[ ]*/''$1'$result); 
    This can be just:
    PHP Code: 
    $result trim($result); 
    Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic

    Huge list of Warez Sites and free Multiposter Templates

  4.     
    #13
    Google Corp.
    Yup, seems to work now I used this to trim the spaces from the beginning and the end:
    PHP Code: 
        $result trim($result); 
    But that brings up another problem, there are extra hyphens at the beginning and the end after the numbers/words under 3chars have been deleted. It needs to trim any remaining hyphens from the beginning and end too, before trimming the whitespace. I tried these lines but neither worked:
    PHP Code: 
        $result trim($result"-"); 
    PHP Code: 
        $result preg_replace('/[-]*(\r{0,1}\n)[-]*/''$1'$result); 
    Life asked Death: "Why do people love me, but hate you?"
    Death responded: "Because you're a beautiful lie and I'm the painful truth."


  5.     
    #14
    Respected Developer
    trim($result) will not only trim spaces but also newlines (\r \n and others) I think. I'll just leave this for litewarez or someone else who is more familiar with PHP.

  6.     
    #15
    Google Corp.
    ^ that shouldn't be a problem since they are only 1-liner's

    thanks for all the help m8


    got it down to this:
    PHP Code: 
    function clean($txt)
    {
        
    // remove everything that is not a word, _, -, whitespace or a number
        
    $result preg_replace('/([^\w\d\s\-]+|\b[\w]{1,3}\b)/'''$txt);
        
    // replace numbers with a space
        
    $result preg_replace('/\d+/'' '$result);
        
    // remove words <= 3 chars
        
    $result preg_replace('/\b[\w]{1,3}\b/'''$result);
        
    // trim spaces
        
    $result preg_replace('/[ ]{2,}/'' '$result);
        
    $result trim($result);
        
        return 
    $result;

    Life asked Death: "Why do people love me, but hate you?"
    Death responded: "Because you're a beautiful lie and I'm the painful truth."


  7.     
    #16
    Respected Developer
    Screw it, bored anyways:
    PHP Code: 
    <?php

    function clean($txt)
    {
        
    // remove everything that is not a word, _, -, whitespace or a number
        
    $result preg_replace('/[^\w\d\s\-]+/'''$txt);
        
    // replace numbers with a space
        
    $result preg_replace('/\d+/'' '$result);
        
    // remove words <= 3 chars
        
    $result preg_replace('/\b\w{1,3}\b/'''$result);
        
    // trim spaces
        
    $result preg_replace('/[ ]{2,}/'' '$result);
        
    // trim -
        
    $result preg_replace('/-{2,}/''-'$result);
        
    // trim spaces and - at the end or beginning of lines
        
    $result preg_replace('/[ \-]*(\r{0,1}\n)[ \-]*/''$1'$result);
        
        return 
    $result;
    }

    ?>
    FYI, $result = trim($result); doesn't do the same thing as the line you replaced it with.

  8.     
    #17
    Google Corp.
    Yeah, but this line doesn't seem to work:
    PHP Code: 
        // trim spaces and - at the end or beginning of lines
        
    $result preg_replace('/[ \-]*(\r{0,1}\n)[ \-]*/''$1'$result); 
    Since its not trimming the spaces from the ends :/

    trim($result) seems to do the trick.
    Life asked Death: "Why do people love me, but hate you?"
    Death responded: "Because you're a beautiful lie and I'm the painful truth."


  9.     
    #18
    Respected Developer
    PHP Code: 
    <?php

    function clean($txt)
    {
        
    // remove everything that is not a word, _, -, whitespace or a number
        
    $result preg_replace('/[^\w\d\s\-]+/'''$txt);
        
    // replace numbers with a space
        
    $result preg_replace('/\d+/'' '$result);
        
    // remove words <= 3 chars
        
    $result preg_replace('/\b\w{1,3}\b/'''$result);
        
    // trim spaces
        
    $result preg_replace('/[ ]{2,}/'' '$result);
        
    // trim -
        
    $result preg_replace('/-{2,}/''-'$result);
        
    // trim spaces and - at the end or beginning of lines
        
    $result preg_replace('/[ \-]*(\r{0,1}\n)[ \-]*/''$1'$result);
        
        return 
    trim($result'- \t\n\r\0\x0B');
    }

    ?>
    The regex only trimmed spaces where there were new lines, not at the beginning or end of the string (which is what trim does).

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Preg and Sql
    By Chris2k in forum Web Development Area
    Replies: 6
    Last Post: 28th Apr 2012, 02:19 PM
  2. Which is the best replace tools
    By tcnnvnn in forum Webmaster Discussion
    Replies: 5
    Last Post: 29th Sep 2011, 09:40 AM
  3. Preg Replace question
    By Porsche_maniak in forum Web Development Area
    Replies: 7
    Last Post: 7th Nov 2010, 08:58 AM
  4. how to replace word in vb4
    By m107 in forum vBulletin
    Replies: 13
    Last Post: 4th Sep 2010, 09:20 AM
  5. how to replace bad words?
    By wman in forum vBulletin
    Replies: 2
    Last Post: 19th Feb 2009, 12:18 PM

Tags for this Thread

BE SOCIAL