|
-
Aug 27th, 2002, 02:20 PM
#1
Thread Starter
Stuck in the 80s
preg_replace
I'm created a bb system and I want the board owner to be able to specify custom bbcode, such as:
Code: @
Replacement: <a href=\\1>\\1</a>
so I have to be able to parse their input into preg strings.
Here is an example of what I have so far:
Example: http://www.vbshelf.com/bb/test.php
Code: http://www.vbshelf.com/bb/test.phps
However, it doesn't quite work. Does anybody have any ideas why?
-
Aug 28th, 2002, 10:36 AM
#2
Fanatic Member
PHP Code:
function ParseCode($text = "Invalid use of Function",$abCode = 1) {
if ($abCode) {
$abArray = array();
$htmlArray = array();
$query = mysql_query("select * from abCode");
for($i=0;$i<mysql_numrows($query);$i++) {
$abTag = mysql_result($query,$i,"abTag");
$htmlTag = mysql_result($query,$i,"htmlTag");
$option = 1;
while (preg_match("/\\{(option|param)\\}/is",$abTag)) {
$abTag = preg_replace("/\\{(option|param)\\}/is","(.*?)",$abTag,1);
$option++;
}
$abArray[$i] = $abTag;
$replace = 1;
while (preg_match("/\\{(option|param)\\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\\{(option|param)\\}/is","\\\\\\\\".$replace,$htmlTag,1);
$replace++;
}
$htmlArray[$i] = $htmlTag;
}
for ($i=0;$i<sizeof($abArray);$i++) {
$abArray[$i] = str_replace("[","\\[",$abArray[$i]);
$abArray[$i] = str_replace("]","\\]",$abArray[$i]);
$abArray[$i] = str_replace("/","\\/",$abArray[$i]);
$text = preg_replace("/".$abArray[$i]."/",$htmlArray[$i],$text);
}
return $text;
}
}
This is what I use in my Bloggernaut Script. All it looks for is the phrases "{option}" and "{param}" (you can find this function plus the function that takes the user input in the functions.php file in my bloggernaut script) and replaces those with the correct \\1 or \\2 accordingly.
When you have the user input his/her tag all you need to check is that the HTML version has the same number of {option} and {param} tags as the bbCode field.
-Matt
-
Aug 28th, 2002, 10:50 AM
#3
Thread Starter
Stuck in the 80s
so you don't know why mine's not working?
It does everything right, but when it displays it just shows \1 instead of the text. and it's bold like it's supposed to be.
I know it has to be something simple.
-
Aug 28th, 2002, 10:51 AM
#4
Thread Starter
Stuck in the 80s
BTW, Matt, when I tried to download Bloggernaut, nothing happened. No download page, no e-mail...nothing.
I put in my correct e-mail and everything.
-
Aug 28th, 2002, 11:12 AM
#5
Thread Starter
Stuck in the 80s
Nevermind, I have it working now.
-
Aug 29th, 2002, 08:26 AM
#6
-
Aug 29th, 2002, 09:28 AM
#7
Thread Starter
Stuck in the 80s
I changed it so it "autodetects" where the numbers should be so the user doesn't have to. It's working pretty good now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|