/    Sign up×
Community /Pin to ProfileBookmark

BBCODE No Code

I am writing my own little mb system for my website… and i allow bbcode, now i was wondering how would i write a nocode tag so that way all the text between the [nocode]TEXT HERE[/nocode] it would escape out the brackets [ and ] so that way the system would not interpret the code.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@temp_user123Jul 03.2007 — Just use [B]htmlspecialchars()[/B] (or [B]htmlentities()[/B]) on the part between the NOCODE tags.
Copy linkTweet thisAlerts:
@JustinauthorJul 03.2007 — That wouldn't work because that just changes < >to &gt; and &lt; and it would keep [ as [. I need to change [ to its escape sequence.. I'll just run the grabbed data through another function to escape those... i was just hoping there was an easy way of doing it.
Copy linkTweet thisAlerts:
@JustinauthorJul 03.2007 — pass the found result from a pre_replace to a funciton with the found result as the paramater.

$parse = preg_replace('/[nocode](.*?)[/nocode]/i', '1', $parse

How would i pass the 1 into a function and what that function returns is what i would replace it with?
Copy linkTweet thisAlerts:
@temp_user123Jul 03.2007 — That wouldn't work because that just changes < >to &gt; and &lt; and it would keep [ as [.[/QUOTE]
I believe [B]htmlentites()[/B] will change those, too.
Copy linkTweet thisAlerts:
@JustinauthorJul 03.2007 — htmlentites() does not deal with [] that is by defualt i don't know if you can tell it to... but all it deals with is quotes slashes and < >.

And at the moment, all i need to do is figure out how to pass a preg_replace to a fucion and then replace using what the function returns... how do you pass what the preg_replace found into the function like

$parse = preg_replace('/[nocode](.*?)[/nocode]/i', '1', $parse);

how would i pass what was found to a function?

I want to do something like:

$parse = preg_replace('/[nocode](.*?)[/nocode]/i', removeBrace('1'), $parse);

But I don't know how i would do that correctly.
Copy linkTweet thisAlerts:
@temp_user123Jul 04.2007 — htmlentites() does not deal with [] that is by defualt i don't know if you can tell it to... but all it deals with is quotes slashes and < >.[/QUOTE]
You're describing the function of [B]htmlspecialchars()[/B] -- not [B]htmlentities()[/B]. However, though [B]htmlentities()[/B] does translate over 100 special characters to their equivalent html entities, I've checked the list of standard named html entities and, sorry to say, brackets are not on that list. So, you win. ?
Copy linkTweet thisAlerts:
@bluestarsJul 04.2007 — Do two steps:

preg_match('/[nocode](.*?)[/nocode]/i',$orig,$matches);

$parse = removeBrace($matches[1]);

preg_replace('/[nocode](.*
?)[/nocode]/i',$parse,$orig);
×

Success!

Help @Justin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...