Scholieren.com forum

Scholieren.com forum (https://forum.scholieren.com/index.php)
-   Software & Hardware (https://forum.scholieren.com/forumdisplay.php?f=20)
-   -   [PHP] HTML/PHP highlighting (https://forum.scholieren.com/showthread.php?t=570811)

Martin 17-08-2003 16:16

[PHP] HTML/PHP highlighting
 
Ik heb een variabele $broncode, daar zit dus "platte" tekst in, maar hoe kan ik deze d.m.v. PHP naar een nette color-coding krijgen?

Mijn broncode:

PHP-code:

<?
    $adres = "http://hottopic.scholieren.com";  
    $openen = fopen("$adres", "r");  
    $broncode = fread($openen, 200000);
    $broncode = nl2br(htmlspecialchars($broncode));

    echo "<table cellpadding=\"0\" cellspacing=\" style=\"border: 1px solid #000000;\" width=\"730\" align=\"center\">";

    $regelarray = explode("\n", $broncode);

    for ($count = 0; $count < count($regelarray); $count ++ )
    {
        $regelnummer = $count+1;

        echo "        <tr valign=\"top\">\n
            <td align=\"center\" bgcolor=\"#BABABA\" width=\"25\" style=\"font-family: Courier; font-size: 12px; line-height: 12px;\" nowrap>$regelnummer</td>
            <td bgcolor=\"#D9D9D9\" width=\"705\" style=\"font-family: Courier New; font-size: 12px; padding-left: 3px; padding-top: 0px; padding-right: 1px; line-height: 12px;\" nowrap>$regelarray[$count]</td>
        </tr>";
    }

    echo "</table>";
?>


Triloxigen 17-08-2003 16:27

De functie gebruiken waarvan ik de naam ben vergeten.. :/

ff denken..

deathz0rz 17-08-2003 16:50

http://nl3.php.net/manual/en/functio...ght-string.php

nee hoor dat ligt niet voor de hand

Martin 17-08-2003 17:19

Citaat:

deathz0rz schreef op 17-08-2003 @ 17:50:
http://nl3.php.net/manual/en/functio...ght-string.php

nee hoor dat ligt niet voor de hand

:rolleyes:

Dat werkt niet .

Mijn code:

PHP-code:

<?
    $adres = "http://hottopic.scholieren.com";  
    $openen = fopen("$adres", "r");  
    $broncode = fread($openen, 200000);
    $broncode = nl2br(htmlspecialchars($broncode));
    
    /* ***************** ADDED PART ***************/
    $broncode = highlight_string($broncode);
    /**********************************************/

    echo "<table cellpadding=\"0\" cellspacing=\" style=\"border: 1px solid #000000;\" width=\"730\" align=\"center\">";

    $regelarray = explode("\n", $broncode);

    for ($count = 0; $count < count($regelarray); $count ++ )
    {
        $regelnummer = $count+1;

        echo "        <tr valign=\"top\">\n
            <td align=\"center\" bgcolor=\"#BABABA\" width=\"25\" style=\"font-family: Courier; font-size: 12px; line-height: 12px;\" nowrap>$regelnummer</td>
            <td bgcolor=\"#D9D9D9\" width=\"705\" style=\"font-family: Courier New; font-size: 12px; padding-left: 3px; padding-top: 0px; padding-right: 1px; line-height: 12px;\" nowrap>$regelarray[$count]</td>
        </tr>";
    }

    echo "</table>";
?>


Enlightenment 17-08-2003 17:51

Check die functie. :)
Citaat:

If the second parameter return is set to TRUE then highlight_string() will return the highlighted code as a string instead of printing it out. If the second parameter is not set to TRUE then highlight_string() will return TRUE on success, FALSE on failure.
Hij print het uit, als je het in een variabele wilt gebruiken moet je het volgende doen:

$bla = highlight_string($broncode,true);

Martin 17-08-2003 21:48

Citaat:

Enlightenment schreef op 17-08-2003 @ 18:51:
Check die functie. :)

Hij print het uit, als je het in een variabele wilt gebruiken moet je het volgende doen:

$bla = highlight_string($broncode,true);

Warning: Wrong parameter count for highlight_string() in c:\apache\htdocs\broncode\code.php on line 21

deathz0rz 17-08-2003 22:05

Citaat:

Martin schreef op 17-08-2003 @ 22:48:
Warning: Wrong parameter count for highlight_string() in c:\apache\htdocs\broncode\code.php on line 21
dan heb je zeker een oude versie van PHP?

je kan ook gewoon het resultaat opvangen met output buffering:

PHP-code:

ob_start();
highlight_string($broncode);
$broncode=ob_get_contents();
while (@
ob_end_clean()); 


Triloxigen 17-08-2003 22:22

dat output buffering verhala gaat ook niet op bij alle servers//

Enlightenment 17-08-2003 22:46

Ouder dan 4.2.0

Pff.. zou ik niet moeten hebben. ;)


Alle tijden zijn GMT +1. Het is nu 09:59.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.