topical media & game development

talk show tell print

professional-search-06-seophp-include-custom-markup.inc.php / php



  <?php
  function custom_markup_translate(str)
  {
    // array with regular expressions that match custom tags
    search = array(
      '#{bold}(.*?){/bold}#is',
      '#{italic}(.*?){/italic}#is', 
      '#{underline}(.*?){/underline}#is',
      '#{heading}(.*?){/heading}#is',
      '#{subheading}(.*?){/subheading}#is',
      '#{link:(.*?)}(.*?){/link}#is',
      '#{elink:(.*?)}(.*?){/elink}#is', 
      '#{unordered-list}(.*?){/unordered-list}\s*#is',
      '#{ordered-list}(.*?){/ordered-list}\s*#is',
      '#\\s*{list-element}(.*?){/list-element}\s*#is',
      '#{picture:(.*?)}#is',
      '#\t#',
      '#{comment}(.*?){/comment}#is'
      );
  
    // array with HTML replacements 
    replace = array(
      '<b>\\1</b>',
      '<i>\\1</i>',
      '<u>\\1</u>',
      '<h1 class=some_class>\\1</h1>', 
      '<h2 class=some_other_class>\\1</h2>',
      '<a href=\'\\1\'>\\2</a>',
      '<a href=\'\\1\' target="_blank">\\2</a>',
      '<ul>\\1</ul>', 
      '<ol>\\1</ol>',
      '<li>\\1</li>',
      '<img src="\\1" border="0">',
      '',
      ''
      );
  
    // perform the replacement
    step_1 = preg_replace(search, replace, str); 
    step_2 = preg_split('#({HTML}.*?{/HTML})#is', step_1, -1, PREG_SPLIT_DELIM_CAPTURE);
  
    return = '';
  
    foreach (step_2 as s2) 
    {
      if (preg_match('#{HTML}#', s2)) 
      { 
        return .= preg_replace('#{/?HTML}#is', '', s2);
      } 
      else 
      {
        return .= nl2br(s2);
      }
    }
  
    // return HTML markup
    return return;
  }
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.