|
|
|
|
![]() ![]() |
Apr 7 2007, 11:17 PM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 36 Joined: 27-December 05 Member No.: 16,252 |
To use this you must have PHP support on your server. Just use this code:
CODE <?php $content = "Hello, World!"; $html = array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]'); $replacements = array ('<b>', '</b>', '<i>', '</i>', '<u>', '</u>'); $content = str_replace($html, $replacements, $content); ?> This code can be very useful. It can be used for word filters to block the use of bad words on your site or for emoticons. |
|
|
|
Apr 9 2007, 04:17 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 293 Joined: 27-January 07 From: Winter is cold here. Member No.: 37,984 ![]() |
So I can just create a php file called whatever.php and put that code in it?
|
|
|
|
Apr 9 2007, 09:16 PM
Post
#3
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 144 Joined: 22-March 07 Member No.: 40,472 |
yes you can m8
but make sure to put it out like this $content = str_replace($html, $replacements, $content); |
|
|
|
Apr 13 2007, 10:02 PM
Post
#4
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,012 Joined: 25-September 05 From: L.A. Member No.: 12,251 |
str replace is bad for bbcode especially when it comes to urls etc.
If you use preg_replace, you can get php to check to make sure it actually has an ending. That way if sombody leaves a [b] tag open, it dosn't parse it out. They would have to close it. Here's the bb code i use on the forums i coded. CODE $main_search=array('/\[b\](.*?)\[\/b\]/is','/\[i\](.*?)\[\/i\]/is','/\[u\](.*?)\[\/u\]/is','/\[img\](.*?)\[\/img\]/is','/\[url\=(.*?)\](.*?)\[\/url\]/is','/\[url\](.*?)\[\/url\]/is','/\[color\=(.*?)\](.*?)\[\/color\]/is','/\[code\](.*?)\[\/code\]/is'); $main_replace=array('<strong>$1</strong>','<em>$1</em>','<u>$1</u>','<img src="$1" style="max-width: 100%" border="0">','<a href="$1">$2</a>','<a href="$1">$1</a>','<font color=$1>$2</font>','<div style="WIDTH: 100%; OVERFLOW: auto"><pre>$1</pre></div>'); $str=preg_replace ($main_search, $main_replace, $str); Str_replace is good for smilies though! |
|
|
|
Apr 13 2007, 10:08 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 293 Joined: 27-January 07 From: Winter is cold here. Member No.: 37,984 ![]() |
Ok! Do they both work though? I used another tutorial here that used preg_replace. They also said it was more better than str_replace. Unholy, you might want ot take his advice!
|
|
|
|
Apr 13 2007, 10:12 PM
Post
#6
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,012 Joined: 25-September 05 From: L.A. Member No.: 12,251 |
Ok! Do they both work though? I used another tutorial here that used preg_replace. They also said it was more better than str_replace. Unholy, you might want ot take his advice! More better? lol If you use preg_replace you'll get a much more professional bb parser. It would be more like trap17's bb. This would be the effect you would get: [b]if this board used str_replace to parse bb code, the rest of this post would be bold because the bold tag would be parsed and replaced into <b> no matter what. |
|
|
|
Apr 13 2007, 10:18 PM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 293 Joined: 27-January 07 From: Winter is cold here. Member No.: 37,984 ![]() |
Ahhh.... Okay. Thanks. I think I will stick with the easyer one.
|
|
|
|
Apr 18 2007, 03:37 AM
Post
#8
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,012 Joined: 25-September 05 From: L.A. Member No.: 12,251 |
The problem with using str_replace for tags like img is you would have to have [img] replace to <img src=" and [ /img] replace to ">. Now if you think about it, if you use that, anybody could easily break your forums by just starting an image tag without ending it. If you write <img src=" in the middle of your code, it's not going to end untill it sees another quote and another greaterthan. If your site uses tables, this could really screw up the site.
P.S. Along with emoticons, str_replace is really good for disabling HTML. CODE $string=str_replace(array("<",">"),array("<",">"),$string);
|
|
|
|
![]() ![]() |
Similar Topics