[PHP] Highlight probleempje...

Pagina: 1
Acties:

  • kaandorp
  • Registratie: November 1999
  • Laatst online: 03-09 22:36
Ik heb de volgende code:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?
<html>
      <head>
      <title></title>
      <link href="styles.css" rel="StyleSheet" type="text/css">
      </head>

      <body>

<?
function colorsource($source)
      {
      clearstatcache();
      if(!file_exists($source))
            {
            return 1;
            }
      $handle=fopen($source,"r"); //open source code
      $size=filesize($source);
      $temp=fread($handle, $size);

      $colorcode=highlight_string($temp); //give the color

      return 0;
      }

echo "<span class=\"bodytext\">";
$colorsource = colorsource("show.php");

$colorsource=str_replace("<code>", "", $colorsource);
$colorsource=str_replace("</code>", "", $colorsource);

echo "</span>";
?>

      </body>
</html>
?>

Het wordt allemaal wel leuk gehighlight, maar die highlight_string() functie zet er de <code> en </code> tags bij. En dat wil ik niet!!
Ik krijg ze ook niet weg met de str_replace.

Iemand een idee?

  • bartware
  • Registratie: Juni 2001
  • Laatst online: 25-03-2023

bartware

@jabber.org

Wat returnt coloursource eigenlijk?
$colorcode wordt nergens meer gebruikt. Moet je daar je str_replace niet op loslaten?

Heb ik me begrepen?
Cycle Vision 2020: 17-20 juli Sportpark Sloten & Wheelerplanet Spaarnwoude


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

is het overloaden van function colorsource met $colorsource wel toegestaan in php :?

Doet iets met Cloud (MS/IBM)


  • kaandorp
  • Registratie: November 1999
  • Laatst online: 03-09 22:36
Heb de code een beetje aangepast:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?
<html>
      <head>
      <title></title>
      <link href="styles.css" rel="StyleSheet" type="text/css">
      </head>

      <body>

<?
function colorsource($source)
      {
      clearstatcache();
      if(!file_exists($source))
            {
            echo "File does not exist!";
            }
      $handle=fopen($source,"r"); //open source code
      $size=filesize($source);
      $temp=fread($handle, $size);

      $coloredsource=highlight_string($temp); //give the color

      return $coloredsource;
      }

echo "<span class=\"bodytext\">";
echo "TEST!<br>\n";
$stringmetcode = colorsource("show.php");

$stringzondercode = ereg_replace("<code>", "", $stringmetcode);

echo "</span>";
?>

      </body>
</html>
?>

Maar het werkt nog steeds niet!! ;(

Maar ik zit me opeens te bedenken dat het misschien met ob_start() enzo wel eens opgelost kan zijn. Ik zie namelijk wel de gekleurde code, maar ik doe nergens echo ;)

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

kaandorp:
Heb de code een beetje aangepast:
code:
1
2
3
4
5
(meuk)
$stringmetcode = colorsource("show.php");

$stringzondercode = ereg_replace("<code>", "", $stringmetcode);
(meuk)
PHP:
1
2
3
<?
$highlighted = preg_replace ( "/<code>((.|\n)*)<\/code>/", "\\1", colorsource ( "show.php" ) );
?>
Maar ik zit me opeens te bedenken dat het misschien met ob_start() enzo wel eens opgelost kan zijn. Ik zie namelijk wel de gekleurde code, maar ik doe nergens echo ;)
Maakt in principe niet uit, maar het is een mogelijkheid.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • bartware
  • Registratie: Juni 2001
  • Laatst online: 25-03-2023

bartware

@jabber.org

Op vrijdag 14 december 2001 14:21 schreef kaandorp het volgende:
Maar ik zit me opeens te bedenken dat het misschien met ob_start() enzo wel eens opgelost kan zijn. Ik zie namelijk wel de gekleurde code, maar ik doe nergens echo ;)
Ja, dat vroeg ik me nog af: hoe komt die meuk tussen de <SPAN> tags, want je echoot nergens iets.....
Hoe zit dat?

Heb ik me begrepen?
Cycle Vision 2020: 17-20 juli Sportpark Sloten & Wheelerplanet Spaarnwoude


  • kaandorp
  • Registratie: November 1999
  • Laatst online: 03-09 22:36
De functie highlight_string() doet dat. Dat is dus erg irritant. Op het moment dat je die functie aanroept word meteen de hele zaak ge-echo-t. Zo kun je dus achteraf niks meer wijzigen. Dit los je op door met ob_start() eerst de output te bufferen en dan met ob_get_contents() de zaak aan een variabele te geven. Dan kun je wel weer string functies er op loslaten. Works for me iig.

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Op vrijdag 14 december 2001 16:00 schreef kaandorp het volgende:
De functie highlight_string() doet dat. Dat is dus erg irritant. Op het moment dat je die functie aanroept word meteen de hele zaak ge-echo-t.
|:( ja dat is waar. Ik dacht dat highlightstring een string teruggaf, maar dawwasniezo....

*gaat in een hoekje zitten en hoopt dat niemand gezien heeft wat hij gezegd heeft*

Een tip die wel ergens op slaat:
gebruik naast ob_* functies ook gewoon de functie highlight_file. Hoef je geen filectrl in te bouwen ;)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz

Pagina: 1