logo sykohpath.com

				where code goes to die
			
	
tagstagstags

Handling Fake Tags

muahahah fixed it all...sorta.  dang, I can't read the form text now...whoops.

Ok, here's now to made "fake" bbcode tags, and autoformat numbered code lines (simply remove the Y in the tag, or make up your own tags to whatever you want):


PHP:
Code Sample:
  1.     //fix html tags for specials
  2.      //faked bbcode
  3.     $text = str_replace("[Ycode]","<code>",$text);
  4.     $text = str_replace("[/Ycode]","</code>",$text);
  5.     $text = str_replace("[Yp]","<p>",$text);
  6.     $text = str_replace("[/Yp]","</p>",$text);
  7.     $text = str_replace("[Ypre]","<pre>",$text);
  8.     $text = str_replace("[/Ypre]","</pre>",$text);
  9.     $text = str_replace("[Ycopy]","©",$text); //copyright symbol
  10.     $text = str_replace("[Yreg]","®",$text); //registered symbol
  11.     $text = str_replace("[Ydeg]","°",$text); //degree symbol
  12.     //numbered code generation
  13.     $pattern = "/[Yncode.*?](.*?)[/Yncode]/";
  14.     preg_match_all($pattern, $text, $matches);
  15.     if(is_array($matches)){
  16.      if(is_array($matches[1])){ //means there are multiple matches
  17.       foreach($matches[1] as $value){
  18.        $replaceString = $value;
  19.        $codeLine = explode("<br>", $value);
  20.        $value = "<ol><label  Sample:</label>";
  21.        foreach($codeLine as $codeRow){
  22.         $value .= "<li><code  . $codeRow . "</code></li>";
  23.        }
  24.        $value .= "</ol>";
  25.        $text = str_replace($replaceString, $value, $text);
  26.       }
  27.      }
  28.     }
  29.     //finally, remove the marking tags!
  30.     $text = str_replace("[Yncode]","",$text);
  31.     $text = str_replace("[/Yncode]","",$text);


CSS:
Code Sample:
  1. code {
  2. font-family: Courier, monospace;
  3. color:#000;
  4. /*font-style: italic;*/
  5. font-size:10pt;
  6. background: url("http://www.sykohpath.com/images/background.jpg") repeat;
  7. margin: 0px 0px 0px 0px;
  8. padding: 0px 0px 0px 10px;
  9. display: block;
  10. border:1px #c01 solid;
  11. }
  12. ol {
  13. background: #c01;
  14. overflow:auto;
  15. font-family:Verdana;
  16. text-decoration: bold;
  17. color:#eee;
  18. margin: 0px 10px 0px 20px;
  19. padding: 0px 2px 2px 25px;
  20. border: 1px #ffccee dashed;
  21. }
  22. ol li {
  23. background: url("http://www.sykohpath.com/images/background.jpg") repeat;
  24. font-size:10px;
  25. font-family:Verdana;
  26. text-decoration: bold;
  27. list-style-type: cjk-ideographic;
  28. }

php, tags, code,


0 comments.