Hello,
While thinking of making a forum one of he problems i can up with was:
How to let the user format the tyext while stopping bad code???
I also discovered that text box input uses /n instead of <br>. So my to questions:
What would be the best way to let certain code through?
My idea was to use magic quotes (or something like it) to convert <br> into <br> then turn
certain bits back into <br> with the replace() (or something like it) function. Is their an easier way?
Thanks in advanced (I have read "common php questions" by Nullworm- but found the bit about this a bit under covered- I understand it was just a reference so we know what to ask for).
EDIT: Just remebered what i was going to say:
How do i convert /n to <br> (YES I DID READ THAT PART FROM NULLWORM).
Magic Quotes- Only for certain bits of text.
Started by bbqroast, Oct 24 2010 11:50 AM
8 replies to this topic
#1
Posted 24 October 2010 - 11:50 AM
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).
|
|
|
#2
Posted 24 October 2010 - 02:20 PM
that's why forums usually use BBcode, as it's just not html-tags, but almost. safer for all.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#3
Posted 24 October 2010 - 11:50 PM
#4
Posted 30 October 2010 - 09:47 AM
If you do want to do it on your own, take a look at this function:
preg_replace($pattern, $replacement, $string);
PHP: preg_replace - Manual
Takumi
preg_replace($pattern, $replacement, $string);
PHP: preg_replace - Manual
Takumi
#5
Posted 01 November 2010 - 11:23 PM
@ORjANT
Yes I guess it is like BBCode any pointers??
@DEViAnT
Yes but is that going to slide into my site perfectly and intergrate keenly with my current login system. Do you have any idea how strange it seems when forums dedicated to coding are made using a code free installer???
Besides I'm having tons of fun making it.
@Takumi
+rep +rep Thanks much
Yes I guess it is like BBCode any pointers??
@DEViAnT
Yes but is that going to slide into my site perfectly and intergrate keenly with my current login system. Do you have any idea how strange it seems when forums dedicated to coding are made using a code free installer???
Besides I'm having tons of fun making it.
@Takumi
+rep +rep Thanks much
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).
#6
Posted 01 November 2010 - 11:35 PM
a pointer for BBcode is actually to php it self... PHP: BBCode - Manual
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#7
Posted 02 November 2010 - 08:18 PM
Actually if you're interested in regular expressions for the matter, I wrote up a quick function more or less 7 years ago when learning regular expressions.
function parse_bbcode($text, $smileys = true)
{
$text = htmlentities($text);
$tags = array(
'#\[b\](.*?)\[/b\]#si' => '<strong>\\1</strong>',
'#\[i\](.*?)\[/i\]#si' => '<em>\\1</em>',
'#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>',
'#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>',
'#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>',
'#\[img\](.*?)\[/img\]#si' => '<img src="\\1" border="0" alt="" />',
'#\[url=(.*?)\](.*?)\[/url\]#si' => '<a href="\\1">\\2</a>',
'#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1" title="Email \\1">\\1</a>',
'#\[code\](.*?)\[/code\]#si' => '<blockquote style="font-face: \'trebuchet ms\'; 40px;margin:6px;color:#575757;margin-left:20px;">\\1</blockquote>',
'#\[align=(.*?)\](.*?)\[/align\]#si' => '<div style="text-align: \\1;">\\2</div>',
'#\[br\]#si' => '<br style="clear: both;" />',
);
foreach ($tags as $search => $replace){
$text = preg_replace($search, $replace, $text);
}
if ($smiley == true) {
$smilies = array(
':)' => '<img src="images/smilies/smile.gif" border="0" height="16" width="16" alt="Smile" title="Smile" />',
':(' => '<img src="images/smilies/sad.gif" border="0" height="16" width="16" alt="Sad" title="Sad" />',
':D' => '<img src="images/smilies/biggrin.gif" border="0" height="16" width="16" alt="Big Grin" title="Big Grin" />',
':S' => '<img src="images/smilies/confused.gif" border="0" height="16" width="16" alt="Confused" title="Confused" />'
// more here
);
foreach ($smilies as $search => $replace){
$text = str_replace($search, $replace, $text);
}
}
//nl2br allows newlines to be converted to quotes
return nl2br($text);
}I left the smiley support in, as it shows how to do simple translations.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 03 November 2010 - 01:16 AM
bbqroast said:
@DEViAnT
Yes but is that going to slide into my site perfectly and intergrate keenly with my current login system. Do you have any idea how strange it seems when forums dedicated to coding are made using a code free installer???
Yes but is that going to slide into my site perfectly and intergrate keenly with my current login system. Do you have any idea how strange it seems when forums dedicated to coding are made using a code free installer???
The text editor can be completely customized down to the bone to look and function exactly how you would want it to. Add your own buttons, change the display, enable/disable what you want, etc.
If you wanna learn, then go for it. If your pressed for time, you might as well use it.
#9
Posted 07 November 2010 - 09:51 PM
Look i have already started and i am going fine.
Thanks NULLW0RM (p.s. where did your spinny worm thing go???)
Thanks NULLW0RM (p.s. where did your spinny worm thing go???)
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).


Sign In
Create Account


Back to top









