Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 11-20-2009, 06:23 PM Custom Markup?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
Hi,

I've created a form which allows user input. However, it grabs any < and > and replaces them with &gt; and &lt;, making it tougher to hack. But I still want users to have access to bold text or italic text.

I've thought about preg_matching everything between two tags, for example, everything between *bold* and */bold* will be bold, and everything between *italic and */italic* will be italic. But that takes time, greatly adding to the loading time of the pages.

I don't care about an extra second, but about 5 seconds is too much. Is there a faster way to do this?

Thanks,

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-20-2009, 06:33 PM Re: Custom Markup?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
just run a replace on BB style code replace [b ] with <b> and [/b ] with </b> etc

Just like this forum does, it adds very very little to load times, microseconds at most.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-20-2009, 06:41 PM Re: Custom Markup?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
That would work, yes, but I want to add more features to it that BBCode doesn't have. Sort of like XML, but I don't want to use that either

So far this is what I have:

PHP Code:

$string 
"The quick brown fox jumped over the lazy dog.";
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/lazy/';
$replacements[0] = 'GIGANTIC';
$replacements[1] = 'yellow';
$replacements[2] = 'stupid';
echo 
preg_replace($patterns$replacements$string); 
And that works, it echoes:
The GIGANTIC yellow dog jumped over the stupid dog
But I want something like this:

PHP Code:

$string 
"This is just normal text *italic*but this is italic*/italic*, and *bold*this is bold*/bold* but this isn't.";
$patterns[0] = '/*bold*/';
$patterns[1] = '/*italic*/';
$patterns[3] = '/*/bold*/';
 
$patterns[4] = '/*/italic*/';
$replacements[0] = '<b>';
$replacements[1] = '<i>';
$replacements[2] = '</b>';
$replacements[2] = '</i>';
echo 
preg_replace($patterns$replacements$string); 
Which is sort of working...
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-20-2009, 07:47 PM Re: Custom Markup?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
In my CMS that I built a form of BBCode into but with more options (199 currently) and end users can add their own.

I use a database table with the tags and the replacement markup in it (and a comment that is used as a "prompt").

Then as the content string is streamed out the code loops through the "tags" and if one exists it runs the replace function.
The whole process takes very little time at all
http://www.modtalk.co.uk/article/c-a...gn/dhtml-tabs/ is served out in a little over 2 seconds, and that includes parsing the code elements as which are done with [code ] [/ code] tags as well.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-20-2009, 07:59 PM Re: Custom Markup?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
Ah, Regular Expressions. I never got those (how they work).

You have
Code:
function _ 
	getElementsByClassName(classname) {
    var a = [];
    var re = new RegExp("\b" + classname + _ 
	"\b");
    var els = document.getElementsByTagName("div");
    for(var i=0;i < els.length; _ 
	i++)
        if(re.test(els[i].className))a.push(els[i]);
    return _ 
	a;
}
show('one');
And right at the line that says
Code:
var re = new RegExp("\b" + classname + _ 
"\b");"
It looks like everything surrounded by "/b" will be...?

Bold? IDK.

Can you help me out with RegExps? I think this is what I need!

Thanks a lot!

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-20-2009, 08:12 PM Re: Custom Markup?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
regular expressions by their nature are "greedy" so if you matched [b at the atart of the string it could match everything in the string upto the LAST [/b.
which is why I don't use them for this kind of thing
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-20-2009, 08:28 PM Re: Custom Markup?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
Yeah, that what I need. I need (pretty much) my own BBCode, except using tags like (b) and (/b) for my [ and ].

I don't want to install BBCode, because that would take a while for me to implement into my script... I'd post my entire script, but it it gigantic. As you said, "In your CMS", I'm making my own CMS, too.
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-21-2009, 06:56 AM Re: Custom Markup?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's actually not that difficult to create your own. Mind you I did have the advantage of such a thing not actually being available (ASP VbScript), so I had no preconceptions of code or structures that may be required to create such a system. Which of course let me be 100% code creative to build my own efficient (IMO) methods.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Custom Markup?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28092 seconds with 12 queries