<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Code The World — Replace bad words]]></title>
		<link>https://codetheworld.com/viewtopic.php?id=18</link>
		<atom:link href="https://codetheworld.com/extern.php?action=feed&amp;tid=18&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Replace bad words.]]></description>
		<lastBuildDate>Sun, 15 Jun 2008 16:16:56 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Replace bad words]]></title>
			<link>https://codetheworld.com/viewtopic.php?pid=161#p161</link>
			<description><![CDATA[<p>lol we should implement that here <img src="https://codetheworld.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p>]]></description>
			<author><![CDATA[null@example.com (Hornet)]]></author>
			<pubDate>Sun, 15 Jun 2008 16:16:56 +0000</pubDate>
			<guid>https://codetheworld.com/viewtopic.php?pid=161#p161</guid>
		</item>
		<item>
			<title><![CDATA[Replace bad words]]></title>
			<link>https://codetheworld.com/viewtopic.php?pid=25#p25</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (hobano)]]></author>
			<pubDate>Sun, 15 Jun 2008 03:01:20 +0000</pubDate>
			<guid>https://codetheworld.com/viewtopic.php?pid=25#p25</guid>
		</item>
	</channel>
</rss>
