Variable MyCode?
PK8 Offline
Junior Member
**
Posts: 13
Joined: Oct 2010
Post: #1
Variable MyCode?
This is probably a pretty insane idea for a MyCode. Hell, I'm not sure if it was ever thought of before. If I'm not making much sense, I blame me being sleepy when I thought of it. I haven't fully thought everything out as I've just thought of it, but again, I hope it makes some sense.

The MyCode would let users define variables (like variables in various programming languages) and then another can refer to it. The syntax could look a little something like this:

Code:
[variable=([a-z0-9]+)]Information that could later be reused in the post.[/variable] <-- Defining a variable.
[variable=([a-z0-9]+)] <-- Referring to a variable.


Example:

Code:
[variable=lorem]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id blandit elit. Nullam euismod urna at leo blandit eget pulvinar neque interdum.[/variable]

[variable=lorem]
[variable=lorem]
[variable=lorem]


I was thinking the variables could be restricted to the post it was defined in, that way other posts can't access them.


MyBB 1.6 + XThreads fan.
01-16-2012 12:07 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Variable MyCode?
For ease with regular expressions you may wish to use different tags for setting and getting the variable.

Lazy example code (PHP 5.3 only cause I'm extra lazy):

PHP Code:
$postvars = array();
$post['message'] = preg_replace_callback('~\[set\=([a-z0-9]+)\](.*?)\[/set\]~si', function($m) use(&$postvars) {
	$postvars[strtolower($m[1])] = $m[2];
}, $post['message']);
$post['message'] = preg_replace('~\[variable=([a-z0-9]+)\]~ie', '$postvars[strtolower(\'$1\')]', $post['message']);


My Blog
(This post was last modified: 01-16-2012 10:23 AM by ZiNgA BuRgA.)
01-16-2012 10:21 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: