Hi, i am building a "pastbin".
First: I'am norwegian, so iam not so good in english :p

But have a problem to highlight the string.
The strings are being insert to a database first.

index.php

echo highlight_string(include 'vis.php');

vis.php:

<?php

$object = mysql_fetch_object($select_query);
echo $object->kode;

?>

The code wil not be coloring :queasy:
Help ?

Whole index code:

<?php error_reporting(E_ALL); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pastebin</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>
<body>

<?php

/***************************************
** KONFIGURASJON
***************************************/


// inkluder funksjoner

$func_inc_fil = "func.php";	
include_once $func_inc_fil;

// mysql
$tjener     = 'localhost'; 
$brukernavn = 'root'; 
$passord    = ''; 
$database   = 'test'; 
$tabell     = 'pastbin';  

$tilkobling = mysql_connect($tjener, $brukernavn, $passord);
$database   = mysql_select_db($database);


$errormld_navn = 'error 1';
/***************************************
** START SCRIPT
***************************************/

// Vis tilkoblingen inneholder feil, vis feilmelding
if(!$tilkobling OR !$database) {
	print (mysql_error());
	die();
}

if(array_key_exists('legg_ode', $_POST))
	{
		$name = htmlspecialchars($_POST['navn'], ENT_QUOTES);
			if(strlen($name) < 3) {
				$error = $errormld_navn;
			}
			else {
		$code = htmlspecialchars($_POST['kode_d'], ENT_QUOTES);

				$sqlinsert = "INSERT INTO ". $tabell ." VALUES ('', '$name', '$code')";
				$query = mysql_query($sqlinsert);

					if(!$query) {
						print (mysql_query());
					}
					else {
					$insert = true;
					}

			}
	}
if(isset($error)) {
	print $error . '<br />';
} else {
if(isset($insert)) {
	print 'Din kode er lagt til!';
} }

form();

if($_GET['kode']) {
	$id = $_GET['kode'];

	$select = "SELECT * FROM ". $tabell ." WHERE id = '". $id ."'";
	$select_query = mysql_query($select);
		if(!$select_query) {
			print (mysql_error());
		}
		else {
		echo highlight_string(include 'vis.php');
		}
}

mysql_close($tilkobling); 

?>

    The problem is that you're expecting [man]include[/man] to return a string, e.g. the contents of the file. If you'll read the manual for include, you'll note that it certainly does not do this.

    Instead, you should look at using [man]highlight_file/man (or at the very least, using a function that actually returns the contents of a file, e.g. [man]file_get_contents/man).

      bradgrafelman;10884063 wrote:

      The problem is that you're expecting [man]include[/man] to return a string, e.g. the contents of the file. If you'll read the manual for include, you'll note that it certainly does not do this.

      Instead, you should look at using [man]highlight_file/man (or at the very least, using a function that actually returns the contents of a file, e.g. [man]file_get_contents/man).

      If i take highlight_file, so wil this be colored:

      <?php
      
      $object = mysql_fetch_object($select_query);
      echo $object->kode;
      
      ?>

      And that wil then be wrong..

        you would want [man]highlight_string/man if you're not actually using a real file.

        $object = msyql_fetch_object($select_query);
        
        highlight_string($object->kode);
          Write a Reply...