<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Code The World — Replace bad words]]></title>
	<link rel="self" href="https://codetheworld.com/extern.php?action=feed&amp;tid=18&amp;type=atom" />
	<updated>2008-06-15T16:16:56Z</updated>
	<generator>PunBB</generator>
	<id>https://codetheworld.com/viewtopic.php?id=18</id>
		<entry>
			<title type="html"><![CDATA[Re: Replace bad words]]></title>
			<link rel="alternate" href="https://codetheworld.com/viewtopic.php?pid=161#p161" />
			<content type="html"><![CDATA[<p>lol we should implement that here <img src="https://codetheworld.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p>]]></content>
			<author>
				<name><![CDATA[Hornet]]></name>
			</author>
			<updated>2008-06-15T16:16:56Z</updated>
			<id>https://codetheworld.com/viewtopic.php?pid=161#p161</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Replace bad words]]></title>
			<link rel="alternate" href="https://codetheworld.com/viewtopic.php?pid=25#p25" />
			<content type="html"><![CDATA[<p>A simple function to replace &quot;bad words&quot;. </p><div class="codebox"><pre><code>function ReplaceBadWords($str, $bad_words, $replace_str){
    if (!is_array($bad_words)){ $bad_words = explode(&#039;,&#039;, $bad_words); }
    for ($x=0; $x &lt; count($bad_words); $x++){
        $fix = isset($bad_words[$x]) ? $bad_words[$x] : &#039;&#039;;
        $_replace_str = $replace_str;
        if (strlen($replace_str)==1){ 
            $_replace_str = str_pad($_replace_str, strlen($fix), $replace_str);
        }
        $str = preg_replace(&#039;/&#039;.$fix.&#039;/i&#039;, $_replace_str, $str);
    }
    return $str;
}
 
 
/*example-start*/
 
/*
** First example:
*/
 
// create some test &quot;bla bla&quot;
$str = &lt;&lt;&lt;EOF
This is an test paragraph,
to test this badwords function.
Some bad words: fuck shit.
Sorry for that ;-)
EOF;
 
// this string will be used to replace the 
// bad words:
$replace_str = &quot;@#$*!&quot;;
 
// create a array with words to replace:
$bad_words = array(&#039;shit&#039;,&#039;fuck&#039;);
 
// execute the function:
print ReplaceBadWords($str, $bad_words, $replace_str);
print &quot;&lt;hr/&gt;\n&quot;;
 
 
/*
Another example:
 
 This tiny example shows to alternatives:
 
 1. You can use a string as source for bad words 
 2. If you give a &quot;replace string&quot; with the length of one letter
    it will automatically repeated to match the bad word length
*/
 
print ReplaceBadWords($str, &#039;fuck,shit,paragraph&#039;, &#039;*&#039;);
 
/*example-end*/</code></pre></div>]]></content>
			<author>
				<name><![CDATA[hobano]]></name>
				<uri>https://codetheworld.com/profile.php?id=17</uri>
			</author>
			<updated>2008-06-15T03:01:20Z</updated>
			<id>https://codetheworld.com/viewtopic.php?pid=25#p25</id>
		</entry>
</feed>
