KingOfHeart Posted February 15, 2011 Share Posted February 15, 2011 I need to get the data between [ozcode] and [/ozcode] I then need to take that information and run this function. OZCode($output); So how would I do this? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 15, 2011 Share Posted February 15, 2011 Well, you're posting in Regex so you at least know that much. Questions: 1. Is it recursive? (That is, can ozcode tags be nested?) 2. What kind of text is inside? Anything? Something specific? 3. Do you want to simply run the function, or do you need its return value inserted in the tag's place? Quote Link to comment Share on other sites More sharing options...
KingOfHeart Posted February 15, 2011 Author Share Posted February 15, 2011 $message = OZFunction($output); $output is the information that's between the tags. OZFunction will take that information and automatically recolor it (kind of like how notepad recolors certain php, C++ text). [ozcode] will work kind of like ,,u] etc. You can use it more then once. $message will end up returning the $output information after it edits all the information to the proper color. So $output can be anything. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 15, 2011 Share Posted February 15, 2011 I'll take that as a "no", "anything", and "yes". PHP 5.3 or what? Quote Link to comment Share on other sites More sharing options...
KingOfHeart Posted February 16, 2011 Author Share Posted February 16, 2011 I believe so. Quote Link to comment Share on other sites More sharing options...
sasa Posted February 16, 2011 Share Posted February 16, 2011 try <?php Function OZCode($output){ static $i = 0; $i++; $output=$output[0]; echo $output, ' - ', $i, "<br />\n"; return $output; } $test = 'I need to get the data between [ozcode] and [/ozcode]I need to get the data between [ozcode] and bla[/ozcode]'; preg_replace_callback('~(?<=\[ozcode\]).*?(?=\[\/ozcode\])~', 'OZCode', $test); ?> Quote Link to comment Share on other sites More sharing options...
KingOfHeart Posted February 18, 2011 Author Share Posted February 18, 2011 Not working the way I need it. I can't get it to recolor and at the same time the [ozcode] tag are still shown. I guess I'll have to show the entire code unfortunately. function bbcode2html($message) { //set limits preg_match_all("/(?<!\\\\)\[size(?::\w+)?=(.*?)\](.*?)\[\/size(?::\w+)?\]/si", $message, $matches); foreach ($matches[1] as $num) { $size = "[size=" . $num . "]"; $maxsize = "[size=20]"; $message = ($num > 20)? str_replace("$size", "$maxsize", $message) : $message; } $preg = array( '/(?<!\\\\)\[color(?::\w+)?=(.*?)\](.*?)\[\/color(?::\w+)?\]/si' => "<span style=\"color:\\1\">\\2</span>", '/(?<!\\\\)\[size(?::\w+)?=(.*?)\](.*?)\[\/size(?::\w+)?\]/si' => "<span style=\"font-size:\\1pt\">\\2</span>", '/(?<!\\\\)\[font(?::\w+)?=(.*?)\](.*?)\[\/font(?::\w+)?\]/si' => "<span style=\"font-family:\\1\">\\2</span>", '/(?<!\\\\)\[align(?::\w+)?=(.*?)\](.*?)\[\/align(?::\w+)?\]/si' => "<div style=\"text-align:\\1\">\\2</div>", '/(?<!\\\\)\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si' => "<span style=\"font-weight:bold\">\\1</span>", '/(?<!\\\\)\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si' => "<span style=\"font-style:italic\">\\1</span>", '/(?<!\\\\)\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si' => "<span style=\"text-decoration:underline\">\\1</span>", '/(?<!\\\\)\[center(?::\w+)?\](.*?)\[\/center(?::\w+)?\]/si' => "<div style=\"text-align:center\">\\1</div>", // [email] '/(?<!\\\\)\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"bb-email\">\\1</a>", '/(?<!\\\\)\[email(?::\w+)?=(.*?)\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"bb-email\">\\2</a>", // [url] '/(?<!\\\\)\[url(?::\w+)?\]www\.(.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"http://www.\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>", '/(?<!\\\\)\[url(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>", '/(?<!\\\\)\[url(?::\w+)?=(.*?)?\](.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\2</a>", // [img] '/(?<!\\\\)\[img(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si' => "<img width = 100 height = 100 src=\"\\1\" alt=\"\\1\" class=\"bb-image\" />", '/(?<!\\\\)\[img(?::\w+)?=(.*?)x(.*?)\](.*?)\[\/img(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" alt=\"\\3\" class=\"bb-image\" />", // [list] '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*<br\s*\/?>\s*)?\[\*|(?:\s*<br\s*\/?>\s*)?\[\/?list)/si' => "\n<li class=\"bb-listitem\">\\1</li>", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/list(?!u|o)\w+)?\](?:<br\s*\/?>)?/si' => "\n</ul>", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/list:u(:\w+)?\](?:<br\s*\/?>)?/si' => "\n</ul>", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/list:o(:\w+)?\](?:<br\s*\/?>)?/si' => "\n</ol>", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?!u|o)\w+)?\]\s*(?:<br\s*\/?>)?/si' => "\n<ul class=\"bb-list-unordered\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list:u(:\w+)?\]\s*(?:<br\s*\/?>)?/si' => "\n<ul class=\"bb-list-unordered\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list:o(:\w+)?\]\s*(?:<br\s*\/?>)?/si' => "\n<ol class=\"bb-list-ordered\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?:)?(:\w+)?=1\]\s*(?:<br\s*\/?>)?/si' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-d\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?:)?(:\w+)?=i\]\s*(?:<br\s*\/?>)?/s' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-lr\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?:)?(:\w+)?=I\]\s*(?:<br\s*\/?>)?/s' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ur\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?:)?(:\w+)?=a\]\s*(?:<br\s*\/?>)?/s' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-la\">", '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[list(?:)?(:\w+)?=A\]\s*(?:<br\s*\/?>)?/s' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ua\">", //line breaks '/\n/' => "<br>", // escaped tags like \[b], \[color], \[url], ... '/\\\\(\[\/?\w+(?::\w+)*\])/' => "\\1" ); $message = preg_replace(array_keys($preg), array_values($preg), $message); return $message; } function OZCoding($input) { // Arrays that hold match values $entity = explode(" ", "AngleMove AngleCollide AllocateStrings CreateEntity CreateEntityWithID ChangeDirection ClearCollisionRect Collide CollideAll CollidePoint CheckForHole CallFunction DeleteEntity GetDamage GetRespawnValue GetLiftLevel GetX GetY GetMoveAngle GetDirection GetSpeed GetSpeedMod GetItem GetImage GetType GetString GetState GetInitialX GetInitialY GetEntityCount GetAnglePointX GetAnglePointY GetWeight GetBounceValue GetValue GetHealth GetMaxHealth GetCurrentEntity GetNextMessage GetGotoNextMessage GetNumNextMessages isOpen isTaken isDead isVisible isActive isCuttable isLarge isPickable isPushed isInteracting MessageMap NextEntity Respawn SetOpenFlag SetTakenFlag SetDeadFlag SetVisibleFlag SetActiveFlag SetCuttableFlag SetLargeFlag SetPickableFlag SetPushedFlag SetInteractingFlag SetDamage SetRespawnValue SetLiftLevel SetX SetY SetPosition SetMoveAngle SetDirection SetSpeed SetSpeedMod SetAngleFromDir SetDirFromAngle SetCollisionRect SetItem SetImage SetType SetString SetActiveDist SetState SetWeight SetBounceValue SetValue SetHealth SetMaxHealth StartEntity isOwned SetOwnedFlag GetParent GetParam SetActiveInGroups"); $functions = explode(" ", "AddAnimframe AKey CreateAnim CreateAnimWithID clamp CreateCounter CreateCounterWithID CheckMask CheckForHoleXY ClearRestartTable CalculateAngle DeleteAnim DrawAnim DrawAnimNoInc deleteproperty DeleteCounter DrawImage DownKey DrawText date existproperty EnterKey FinishedAnim funcidx FirstRun FadeTo FinishedReading GetAnimImage GetAnimCount GetMaxAnim GetAnimWidth GetAnimHeight getchar getstring getvalue getarg getproperty GetCounterValue GetWidth GetHeight GetWorldX GetWorldY GetGroupMinX GetGroupMinY GetGroupMaxX GetGroupMaxY GetPauseLevel GetLowerLevelX GetLowerLevelY GetLastAnswer GetMinuteCount GetPlayerName GetHourCount GetDayCount GetGlobal GetLocal heapspace IncrementAnim IncCounterTarget IncCounterValue InitialPlayerX InitialPlayerY InitTextBox LeftKey min max numargs NearPoint print printf PutSprite PlaySound PlayMusic QKey random RightKey SetAnimSpeed SetAnimCount SetAnimDirection SetAnimLoop setarg strlen strcmp strcpy strpack strunpack swapchars setproperty SetCounterMin SetCounterMax SetCounterValue SetCounterTarget SetCounterSpeed SKey SetQKey SetAKey SetSKey SetWKey SetEnterKey SetUpKey SetDownKey SetLeftKey SetPlayerName SetRightKey SetWorldX SetWorldY SetPauseLevel SetRestartTable SetRestartPoint SetLowerLevel SetTextBoxColor SetMinuteCount SetHourCount SetDayCount SetDayLength SetGlobal SetLocal SetMusicVolume SetMusicFadeSpeed tolower toupper ToString ToFile TextFile TestFunc time tickcount UpKey UpdateWorldCo WKey Wipe GetTimeDelta floatstr floatround DrawRectangle DrawLine SetTextSize EnableControls DrawBitmapText SetFloat GetFloat SetSpriteAlpha GetCounterMin"); $enum = explode(" ", "black blue cyan green magenta red yellow white chasing dead dying falling falling2 hit jumping knocked lifting standing swimming standLift using walking walkLift scared spining drowning doorType enemyType itemType npcType otherType playerType weaponType switchType warpType east north northeast northwest south southeast southwest west waiting stunned frozen burning sleeping riding wishing pushed pushing floating leaping collecting pulling diveingstill diveingmove"); $keycode = explode(" ", "assert break case char continue default defined do else exit for goto if return sizeof sleep switch while"); $keyword = explode(" ", "false true cellbits cellmax cellmin charbits charmax charmin debug _Small scope_keywords bool const enum fixed float forward native new operator this public static stock"); $out = $input; $out = str_replace("<","<",$out); $out = str_replace(">",">",$out); $out = str_replace("<pre>","<pre>",$out); $out = str_replace("</pre>","</pre>",$out); // Fix "'s $max = strlen($out); $step = 0; $temp = $out; $out = ""; for($i = 0; $i < $max; $i++) { if($step == 0) { if(ord(substr($temp, $i, 1)) == 226) { $temp2 = substr($temp, $i, 1); $step++; } else $out .= substr($temp, $i, 1); } else if($step == 1) { $temp2 .= substr($temp, $i, 1); if(ord(substr($temp, $i, 1)) == 128) { $step++; } else { $out .= $temp2; $step = 0; } } else if($step == 2) { $temp2 .= substr($temp, $i, 1); if(ord(substr($temp, $i, 1)) == 156 || ord(substr($temp, $i, 1)) == 157) $out .= "\""; else $out .= $temp2; $step = 0; } } // Fix Tabs $max = strlen($out); $temp = $out; $out = ""; for($i = 0; $i < $max; $i++) { if(ord(substr($temp, $i, 1)) == 9) $out .= " "; else $out .= substr($temp, $i, 1); } // Handle " $temp = explode("\"", $out); $out = ""; $in = 0; $i = 0; $com = 0; while($i < count($temp)) { if(count($temp) == 1) $out = $temp[$i]; else { $j = $i; $tmp3 = ""; while(explode("\n", $temp[$j]) == 1) { $tmp3 = $temp[$j].$tmp3; $j--; } $tmp3 = $temp[$j].$tmp3; $temp2 = explode("\n", $tmp3); $com = commented($temp2[count($temp2)-1], $com); if($in == 0 && !$com && $i < (count($temp)-1)) { $in = 1; $out .= $temp[$i]."\"<span class=\"ozquote\">"; } else if($in == 1 && $i < (count($temp)-1) && !$com) { $in = 0; $out.= $temp[$i]."</span>\""; } else if($com && $i < (count($temp)-1)) $out .= $temp[$i]."\""; else $out .= $temp[$i]; } $i++; } // Handle ' $temp = explode("'", $out); $in = 0; $i = 0; $com = 0; while($i < count($temp)) { if($i == 0 && count($temp) > 1) $out = $temp[$i]."'"; else if(count($temp) == 1) $out = $temp[$i]; else { $com = commented($temp[$i], $com); if($in == 0 && !$com && $i < (count($temp)-1)) { $in = 1; $out .= "<span class=\"ozquote\">".$temp[$i]."</span>'"; } else if($in == 1 && $i < (count($temp)-1) && !$com) { $in = 0; $out.= $temp[$i]."'"; } else $out .= $temp[$i]; } $i++; } // Entity functions for($i = 0; $i < count($entity); $i++) { $temp = explode($entity[$i], $out); $j = 0; $q = 0; $sq = 0; $com = 0; while($j < count($temp)) { if($j == 0) $out = $temp[$j]; else { $temp2 = explode("\n", $temp[($j-1)]); $com = commented($temp2[count($temp2)-1], $com); $before = ord(substr($temp[($j-1)], -1)); $after = ord(substr($temp[$j], 0, 1)); if(notFunc($before, $after) || isodd($q) || isodd($sq) || $com > 0) $out .= $entity[$i].$temp[$j]; else $out .= "<span class=\"ozentity\">".$entity[$i]."</span>".$temp[$j]; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $j++; } } // Functions for($i = 0; $i < count($functions); $i++) { $temp = explode($functions[$i], $out); $j = 0; $q = 0; $sq = 0; $com = 0; while($j < count($temp)) { if($j == 0) $out = $temp[$j]; else { $temp2 = explode("\n", $temp[($j-1)]); $com = commented($temp2[count($temp2)-1], $com); $before = ord(substr($temp[($j-1)], -1)); $after = ord(substr($temp[$j], 0, 1)); if(notFunc($before, $after) || isodd($q) || isodd($sq) || $com > 0) $out .= $functions[$i].$temp[$j]; else $out .= "<span class=\"ozfunction\">".$functions[$i]."</span>".$temp[$j]; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $j++; } } // Key Codes for($i = 0; $i < count($keycode); $i++) { $temp = explode($keycode[$i], $out); $j = 0; $q = 0; $sq = 0; $com = 0; while($j < count($temp)) { if($j == 0) $out = $temp[$j]; else { $temp2 = explode("\n", $temp[($j-1)]); $com = commented($temp2[count($temp2)-1], $com); $before = ord(substr($temp[($j-1)], -1)); $after = ord(substr($temp[$j], 0, 1)); if(notFunc($before, $after) || isodd($q) || isodd($sq) || $com > 0) $out .= $keycode[$i].$temp[$j]; else $out .= "<span class=\"ozkeycode\">".$keycode[$i]."</span>".$temp[$j]; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $j++; } } // Keywords for($i = 0; $i < count($keyword); $i++) { $temp = explode($keyword[$i], $out); $j = 0; $q = 0; $sq = 0; $com = 0; while($j < count($temp)) { if($j == 0) $out = $temp[$j]; else { $temp2 = explode("\n", $temp[($j-1)]); $com = commented($temp2[(count($temp2)-1)], $com); $before = ord(substr($temp[($j-1)], -1)); $after = ord(substr($temp[$j], 0, 1)); if(notFunc($before, $after) || isodd($q) || isodd($sq) || $com > 0) $out .= $keyword[$i].$temp[$j]; else $out .= "<span class=\"ozkey\">".$keyword[$i]."</span>".$temp[$j]; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $j++; } } // Enums for($i = 0; $i < count($enum); $i++) { $temp = explode($enum[$i], $out); $j = 0; $q = 0; $sq = 0; $com = 0; while($j < count($temp)) { if($j == 0) $out = $temp[$j]; else { $temp2 = explode("\n", $temp[($j-1)]); $com = commented($temp2[count($temp2)-1], $com); $before = ord(substr($temp[($j-1)], -1)); $after = ord(substr($temp[$j], 0, 1)); if(notFunc($before, $after) || isodd($q) || isodd($sq) || $com > 0) $out .= $enum[$i].$temp[$j]; else $out .= "<span class=\"ozenum\">".$enum[$i]."</span>".$temp[$j]; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $j++; } } // Handle /* $temp = explode("/*", $out); $out = $temp[0]; $i = 1; $q = 0; $sq = 0; while($i < count($temp)) { if(isodd($q) || isodd($sq)) $out .= "/*".$temp[$i]; else $out .= "<span class=\"ozcomment\">/*".$temp[$i]; $i++; $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); } // Handle */ $temp = explode("*/", $out); $out = ""; $i = 0; $q = 0; $sq = 0; while($i < (count($temp)-1)) { if(isodd($q) || isodd($sq)) $out .= $temp[$i]."*/"; else $out .= $temp[$i]."*/</span>"; $i++; $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); } $out .= $temp[$i]; // Handle # $temp = explode("\n", $out); $out = ""; $i = 0; $c = 0; $com = 0; $q = 0; $sq = 0; while($i < count($temp)) { $temp2 = explode("#", $temp[$i]); $com &= 2; if(count($temp2) > 1) { $keyed = 0; $j = 1; $com = commented($temp2[0], $com); $out .= $temp2[0]; while($j < count($temp2)) { if(!$com && !$keyed && !isodd($q) && !isodd($sq)) { $out .= "<span class=\"ozkey\">#".$temp2[$j]; $keyed = 1; } else $out .= "#".$temp2[$j]; $com = commented($temp2[$j], $com); $j++; } $out .= "</span>"; if($i < (count($temp)-1)) $out .= "\n"; } else { $out .= $temp[$i]; if($i < (count($temp)-1)) $out .= "\n"; } $i++; $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); } // Handle // $temp = explode("\n", $out); $out = ""; $i = 0; $c = 0; $q = 0; $sq = 0; while($i < count($temp)) { $temp2 = explode("//", $temp[$i]); if(count($temp2) > 1) { $keyed = 0; $j = 1; $out .= $temp2[0]; while($j < count($temp2)) { if(!$com && !$keyed && !isodd($q) && !isodd($sq)) { $out .= "<span class=\"ozcomment\">//".$temp2[$j]; $keyed = 1; } else $out .= "//".$temp2[$j]; $j++; } if($keyed) $out .= "</span>"; if($i < (count($temp)-1)) $out .= "\n"; } else { $out .= $temp[$i]; if($i < (count($temp)-1)) $out .= "\n"; } $z = $q; $q += countquote($temp[$j], $q, $sq); $sq += countsquote($temp[$j], $sq, $z); $i++; } // Handle Tab $temp = explode(" ", $out); $out = ""; $i = 0; while($i < count($temp)-1) { $out .= $temp[$i] . " "; $i++; } $out .= $temp[$i]; // Handle \n $temp = explode("\n", $out); $out = ""; $i = 0; while($i < count($temp)-1) { if($i == 0 && $temp[$i] == "") $out .= $temp[$i]; else $out .= $temp[$i] . "<br>"; $i++; } $out .= $temp[$i]; return $out; } function commented($string, $a) { $b = $a; $tmp = explode("//", $string); if(count($tmp) > 1) $b |= 1; $tmp = explode("/*", $string); if(count($tmp) > 1) $b |= 2; $tmp = explode("*/", $string); if(count($tmp) > 1) $b &= 1; $tmp = explode("\n", $string); if(count($tmp) > 1) $b &= 2; return $b; } function notFunc($a, $b) { $no = 0; if($a == 34 || $b == 34) $no = 1; if($a > 47 && $a < 58) $no = 1; if($a > 64 && $a < 91) $no = 1; if($a > 96 && $a < 123) $no = 1; if($b > 47 && $b < 58) $no = 1; if($b > 64 && $b < 91) $no = 1; if($b > 96 && $b < 123) $no = 1; return $no; } function countquote($string, $a, $b) { $q = $a; $sq = $b; $t = 0; $tmp = explode("'", $string); $i = 0; while($i < count($tmp)) { if(!isodd($sq)) { $tmp2 = explode("\"", $tmp[$i]); $t += count($tmp2) - 1; $q += count($tmp2) - 1; } if(!isodd($q)) $sq++; $i++; } return $t; } function countsquote($string, $a, $b) { $q = $b; $sq = $a; $t = 0; $tmp = explode("\"", $string); $i = 0; while($i < count($tmp)) { if(!isodd($q)) { $tmp2 = explode("'", $tmp[$i]); $t += count($tmp2) - 1; $sq += count($tmp2) - 1; } if(!isodd($sq)) $q++; $i++; } return $t; } function isodd($a) { $b = $a & 1; return $b; } Before you say, wtf, let me explain it a bit. None of these scripts are mine. The bbcode2html takes bbcodes and turns them into html codes. I wasn't sure on how to limit the command so that limit code is mine. OZCoding takes certain key words and recolors them. This works 90% but unless if you want a challenge, I don't expect any fixups at this point. http://openzelda.thegaminguniverse.org/functions.php Look at "public" to see that small bug. Everything after /* and before */ should be all green. Anyways in the tutorial section you can use bbcodes, including my custom [ozcode]. However so far I can't get the recoloring to work. http://openzelda.thegaminguniverse.org/tutorials.php?name=&type=0&order=0&dir=0&id=3 I tried this for testing since I need it to return, not echo. Function OZCode($output){ static $i = 0; $i++; $output=$output[0]; return $output; } $test = 'I need to get the data between [ozcode] and [/ozcode]I need to get the data between [ozcode] and bla[/ozcode]'; $msg = preg_replace_callback('~(?<=\[ozcode\]).*?(?=\[\/ozcode\])~', 'OZCode', $test); echo $msg; Quote Link to comment Share on other sites More sharing options...
KingOfHeart Posted February 21, 2011 Author Share Posted February 21, 2011 I found another code that might help me. <?php $input = "text[ozcode] red [/ozcode]"; function parseTagsRecursive($input) { $regex = "~(?<=\[ozcode\]).*?(?=\[\/ozcode\])~"; if (is_array($input)) { $input = '<div style="color: red">'.$input[1].'</div>'; } return preg_replace_callback($regex, 'parseTagsRecursive', $input); } $output = parseTagsRecursive($input); echo $output; ?> However it does color anything red. Original code. <?php $input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain"; function parseTagsRecursive($input) { $regex = '#\ [indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent] #'; if (is_array($input)) { $input = '<div style="margin-left: 10px">'.$input[1].'</div>'; } return preg_replace_callback($regex, 'parseTagsRecursive', $input); } $output = parseTagsRecursive($input); echo $output; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.