---
title: "pastebin script"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/151184-pastebin-script"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "kjelle"
published: "2006-09-11T10:41:08.000Z"
updated: "2006-09-11T15:57:56.000Z"
replies: 5
views: 413
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/151184-pastebin-script"
---

# pastebin script

## #1 — kjelle, 2006-09-11T10:41Z

hay!

Nån som har nått pastebinscript liggande som dom vill dela med sej av til mej?

et som highlightar php kod..

/kjelle

Permalänk: https://www.webforum.nu/p/151184

## #2 — sl0k, 2006-09-11T10:56Z

Brukar använda mig av följande .. 

```php
<?php
error_reporting(E_ALL);
if (isset($_GET['file']) && is_readable(basename($_GET['file']))) {
    $filename = basename($_GET['file']);
    highlight_with_linenum($filename);
}
else {
    $dir = rec_scandir("."); // directory to list 
    array_ukmultisort($dir, "cmp");
    foreach ($dir as $file) {
        echo "<a href=\"?file=$file\">$file</a><br />\n";
    }
}

function highlight_with_linenum($file) {
    $count = 1;
    $lines = "";
    $filen = file($file);
    foreach ($filen as $line) {
        $lines .= $count . "<br />";
        $count++;
    }
    $contents = highlight_file($file, TRUE);
    echo '<table><tr><td><code>' .
            $lines . '</code></td><td>' .
            $contents . '</td></tr></table>';
    
}

function rec_scandir($dir)
{
    $files = array();
    if ( $handle = opendir($dir) ) {
        while ( ($file = readdir($handle)) !== false ) {
            if ( $file != ".." && $file != "." && $file{0} != ".") {
                if ( is_dir($dir . "/" . $file) ) {
                    // $files[$file] = rec_scandir($dir . "/" . $file);
                }else {
                    $files[] = $file;
                }
            }
        }
        closedir($handle);
        return $files;
    }
}

function cmp($a, $b)
{
    if ( is_string($a) && is_string($b) ) {
        return strcmp($a, $b) > 0 ? 1 : -1; 
    }elseif ( is_int($a) && is_int($b) ) {
        return $a > $b ? 1 : -1;
    }elseif ( is_int($a) && is_string($b) ) {
        return 1;
    }elseif ( is_string($a) && is_int($b) ) {
        return -1;
    }else {
        return 0;
    }
}

function array_ukmultisort(&$arr, $func) {
    uksort($arr, $func);
    while ( list($key, $val) = each($arr) ) {
        if ( is_array($val) ) {
            array_ukmultisort($arr[$key], $func);
        }
    }
}
?>
```

Permalänk: https://www.webforum.nu/p/1866253

## #3 — kjelle, 2006-09-11T11:22Z

tjo på'rei!

ute efter nått komplett script..

nån?

Permalänk: https://www.webforum.nu/p/1866269

## #4 — Fuel, 2006-09-11T11:31Z

...

Bilagor:

- [hightlighter.png](https://www.webforum.nu/a/12082.png)

Permalänk: https://www.webforum.nu/p/1866271

## #5 — sl0k, 2006-09-11T12:17Z

> **Fuel skrev:**
>
> du sl0k ...   :q  jag döpte filen till highlight.php .. då buggade det ur rejält   :e

ok .. vad var det som inte fungerade? just filnamnet bör inte ha ngn betydelse

Permalänk: https://www.webforum.nu/p/1866286

## #6 — stevenet, 2006-09-11T15:57Z

Pastebin.com's kod finns för nedladdning här: <http://pastebin.com/pastebin.php?help=1>

Permalänk: https://www.webforum.nu/p/1866335

---

Tråden på webben: https://www.webforum.nu/amne/php/151184-pastebin-script
