Results 11 to 18 of 18
-
8th Aug 2010, 10:14 PM #11Respected 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;
}
?>
-
8th Aug 2010, 10:19 PM #12Respected DeveloperWebsite's:
wrzc.orgTutorial How to SEO your Warez Site a guide to help you increase your organic traffic
Huge list of Warez Sites and free Multiposter Templates
-
8th Aug 2010, 10:21 PM #13OPGoogle Corp.
Yup, seems to work now I used this to trim the spaces from the beginning and the end:
PHP Code:$result = trim($result);
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."
-
8th Aug 2010, 10:26 PM #14Respected 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.
-
8th Aug 2010, 10:27 PM #15OPGoogle 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."
-
8th Aug 2010, 10:37 PM #16Respected 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;
}
?>
-
8th Aug 2010, 10:44 PM #17OPGoogle 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);
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."
-
8th Aug 2010, 10:47 PM #18Respected DeveloperPHP 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');
}
?>
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Preg and Sql
By Chris2k in forum Web Development AreaReplies: 6Last Post: 28th Apr 2012, 02:19 PM -
Which is the best replace tools
By tcnnvnn in forum Webmaster DiscussionReplies: 5Last Post: 29th Sep 2011, 09:40 AM -
Preg Replace question
By Porsche_maniak in forum Web Development AreaReplies: 7Last Post: 7th Nov 2010, 08:58 AM -
how to replace word in vb4
By m107 in forum vBulletinReplies: 13Last Post: 4th Sep 2010, 09:20 AM -
how to replace bad words?
By wman in forum vBulletinReplies: 2Last Post: 19th Feb 2009, 12:18 PM
themaPoster - post to forums and...
Version 5.22 released. Open older version (or...