Results 1 to 2 of 2

Thread: PCRE formatting

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default PCRE formatting

    PCRE is a rather processor heavy calculation for PHP as is GD image processing. I have a program on my site that formats the sample code on my site to look something like the formatted code seen in forums. I do this by encapsulating the code in CODE brackets, which is then inserted into the database. When the code is retrieved for viewing it is formatted using PCRE, but I do try to use str_replace() where possible. If I want to edit the text then the code is not PCRE formatted, so that I can see the CODE markings. The CODE markings are what sets the code aside for formatting.

    Does this sound like the right way to go about using my PCRE for formatting my code example scripts or am I just wasting resources?
    Last edited by james438; 11-13-2009 at 10:47 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    My question is now moot. I found a way to reformat the PCRE and replace it all with variations of str_replace().

    Here is an abridged version of what my code now looks like

    PHP Code:
    <?php
    $i
    =1;
    $summary explode("CODE",$summary);
    $a=count($summary);
    while (
    $i<$a)
    {
    #### change the [CODE] areas to display returns.

       
    $summary[$i] = htmlentities($summary[$i]);
       
    $summary[$i] = str_replace("\r\n","<br>",$summary[$i]); // goes to next line and to the leftmost margin
       
    $summary[$i] = str_replace("  ","&nbsp;&nbsp;",$summary[$i]);

    $i=$i+2;
    }
    $i=0;
    while (
    $i<$a)
    {
    if (
    $i%== 0
    {

    ####changes the non [code] sections to display returns
    $k="**";
    $summary[$i]=str_replace("\r\n","<br>",$summary[$i]);
    $summary[$i]=str_replace('  ',"$k",$summary[$i]);
    }
    else 
    $summary[$i]= "<div class=withborder>$summary[$i]</div>"#### adds CSS to the [CODE] areas.
    $i=$i+1;
    }
    $summary implode (" ",$summary);
    echo 
    "$summary";
    ?>
    To choose the lesser of two evils is still to choose evil. My personal site

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •