Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2009, 05:35 AM   PM User | #1
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
func.displayCode.php

PHP Code:
<?php

//http://www.actwebdesigns.co.uk
//luke@actwebdesigns.co.uk
//
//<style type="text/css">
//pre.odd { background-color: #F4F4F4; }
//pre.even { background-color: #a0d3a5; }
//pre.even, pre.odd { margin:0; padding:5px; font-size:12px; color:#404040; border-top:1px solid #404040;}
//div.codeBlock { width:800px; overflow:auto; margin:0 auto; border:1px solid #404040; border-top:none;}
//pre span.lineNo { color:#C60; }
//</style>

function displayCode($url)
{
    if(
file_exists($url))
    {
        
$data file_get_contents($url);
        
$lines explode(PHP_EOL$data);
        
$x=1;
        
$y=1;
        
$return "<div class=\"codeBlock\">\n";
        foreach(
$lines as $line)
        {
            if(
$x!==1)
            {
                
$lineTest trim($line);
                if(!empty(
$lineTest))
                {
                    
$line str_replace("&""&amp;"$line);
                    
$line str_replace("/""/"$line);
                    
$line str_replace("<""&lt;"$line);
                    
$line str_replace(">""&gt;"$line);
                    if((
$x 1)==1)
                        
$class "even";
                    else
                        
$class "odd";
                    if(
preg_match("#(^\s*&\#0047;&\#0047)|(^\s*\#)#is"$line$match))
                    {
                        
$return .= "<pre class=\"".$class." comment\"><span class=\"lineNo\">".$y."</span> ".str_replace("/""/"$line)."</pre>\n";
                    }
                    else
                    {
                        
$return .= "<pre class=\"".$class."\"><span class=\"lineNo\">".$y."</span> ".str_replace("/""/"$line)."</pre>\n";
                    }
                    
$y++;
                }
                else
                {
                    
$x++;
                }
            }
            
$x++;
        }
        
$return .= "</div>\n";
        
$return preg_replace("#(\s*)@?([a-z]+(?:[a-z]|[0-9]|_)*)(\s*)\(([^\)]*)\)#is""\\1<span class=\"function\">\\2\\3</span>(\\4)"$return);
        
$return preg_replace("#\s*(\$[^\s]*)#is"" <span class=\"variable\">\\1</span>"$return);
        return 
$return;
        
    }
    else
    {
        return 
"unknown path given";    
    }                   
}

//echo displayCode("../dir/to/page.php");
?>
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 

Last edited by Phil Jackson; 10-22-2009 at 07:15 AM..
Phil Jackson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:37 PM.


Advertisement
Log in to turn off these ads.