blogblogblog SyKoHPaTh

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]","",$text);
  4. $text = str_replace("[/Ycode]","",$text);
  5. $text = str_replace("[Yp]","

    ",$text);

  6. $text = str_replace("[/Yp]","

    ",$text);
  7. $text = str_replace("[Ypre]","
    ",$text);
  8. $text = str_replace("[/Ypre]","",$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("
    ", $value);
  20. $value = "
    1. foreach($codeLine as $codeRow){
    2. $value .= "
    3. ";
    4. }
    5. $value .= "
    ";
  21. $text = str_replace($replaceString, $value, $text);
  22. }
  23. }
  24. }
  25. //finally, remove the marking tags!
  26. $text = str_replace("[Yncode]","",$text);
  27. $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