...

View Full Version : Resolved Display multiple highlight_file()



Craigy
06-23-2010, 11:08 AM
When I try and use highlight_file() more than once I get http 500 internal server error.
Is it possible to show 2 files in 1 page, or have I made a mistake in my coding?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>WebPage</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h2 class="title"><a href="#">Edit</a></h2>
<h3>Data in MySQL </h3>
<h1>update.php</h1>
<?php

function string_syntax_xhtml( $string, $return = false ) {
$highlight = highlight_string( $string, true );
$replace = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$highlight
);
if( $return ) {
return $replace;
}
echo $replace;
return true;
}

function file_syntax_xhtml( $path, $return = false ) {
return string_syntax_xhtml( file_get_contents( $path ), $return );
}

string_syntax_xhtml( file_get_contents( 'update.php' ) );

?>
<p></p>
<h1>updated.php</h1>
<br>
<?php

function string_syntax_xhtml( $string, $return = false ) {
$highlight = highlight_string( $string, true );
$replace = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$highlight
);
if( $return ) {
return $replace;
}
echo $replace;
return true;
}

function file_syntax_xhtml( $path, $return = false ) {
return string_syntax_xhtml( file_get_contents( $path ), $return );
}
string_syntax_xhtml( file_get_contents( 'updated.php' ) );

?>
</body>
</html>

Rowsdower!
06-23-2010, 01:14 PM
When I try and use highlight_file() more than once I get http 500 internal server error.
Is it possible to show 2 files in 1 page, or have I made a mistake in my coding?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>WebPage</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h2 class="title"><a href="#">Edit</a></h2>
<h3>Data in MySQL </h3>
<h1>update.php</h1>
<?php

function string_syntax_xhtml( $string, $return = false ) {
$highlight = highlight_string( $string, true );
$replace = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$highlight
);
if( $return ) {
return $replace;
}
echo $replace;
return true;
}

function file_syntax_xhtml( $path, $return = false ) {
return string_syntax_xhtml( file_get_contents( $path ), $return );
}

string_syntax_xhtml( file_get_contents( 'update.php' ) );

?>
<p></p>
<h1>updated.php</h1>
<br>
<?php

function string_syntax_xhtml( $string, $return = false ) {
$highlight = highlight_string( $string, true );
$replace = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$highlight
);
if( $return ) {
return $replace;
}
echo $replace;
return true;
}

function file_syntax_xhtml( $path, $return = false ) {
return string_syntax_xhtml( file_get_contents( $path ), $return );
}
string_syntax_xhtml( file_get_contents( 'updated.php' ) );

?>
</body>
</html>


You are defining the same functions twice. You only need to define them once and then you can call them all you like. Try this instead:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>WebPage</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h2 class="title"><a href="#">Edit</a></h2>
<h3>Data in MySQL </h3>
<h1>update.php</h1>
<?php
function string_syntax_xhtml( $string, $return = false ) {
$highlight = highlight_string( $string, true );
$replace = str_replace(
array( '<font color="', '</font>' ),
array( '<span style="color: ', '</span>' ),
$highlight
);
if( $return ) {
return $replace;
}
echo $replace;
return true;
}

function file_syntax_xhtml( $path, $return = false ) {
return string_syntax_xhtml( file_get_contents( $path ), $return );
}
string_syntax_xhtml( file_get_contents( 'update.php' ) );
?>
<p></p>
<h1>updated.php</h1>
<br>
<?php
string_syntax_xhtml( file_get_contents( 'updated.php' ) );
?>
</body>
</html>

Craigy
06-23-2010, 01:30 PM
That now displays them both perfectly, thank you for the help.

Syed.Hussim
06-23-2010, 01:34 PM
Yes becuase, highlight_file uses internal output buffering.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum