PHP Code in HTML?

röme

Grünschnabel
Kann man PHP Code mit HTML Darstellen oder muss man dass mit PHP machen?
Damit ihr wisst worum es geht noch ein Beispiel:

PHP:
<?php
include('datei.php');
echo 'Wie macht man sowas?' ;  //Geht das mit HTML oder PHP?
?>
 
Wenn du sowas nutzen willst, mußt du deine html-Datei in php ändern, also anstatt index.html --> index.php
 
nö ich mcöhte nicht eine php datei machen, dass habe ich schon.

Ich möchte das genauso darstellen wie es oben ist. Dass es so ausgegeben wird. Um alles mit HTML einzufärben geht das ja vielzulang.

EDIT:
Ich hab mal im Parser des vb WYSIWYG Editor nachgekuckt. Aber daraus werde ich nicht schlau:

PHP:
<?php
.........

// ###################### Start bbcodehandler_php #######################
function handle_bbcode_php($code)
{
	global $vboptions, $vbphrase, $stylevar, $highlight_errors;
	static $codefind, $codereplace, $regex, $regexreplace;

	// remove empty codes
	if (trim($code) == '')
	{
		return '';
	}

	//remove smilies
	$code = strip_smilies(str_replace('\\"', '"', $code));

	// get rid of leading newlines
	$code = preg_replace("#^(( )*<br[^>]*>\r\n)*#s", '', chop($code));

	if (!is_array($codefind))
	{
		$codefind = array(
			'<br>',		// <br> to nothing
			'<br />',	// <br /> to nothing
			'&gt;',		// &gt; to >
			'&lt;',		// &lt; to <
			'&amp;',	// &amp; to &
			'&quot;',	// &quot; to "
		);
		$codereplace = array(
			'',
			'',
			'>',
			'<',
			'&',
			'"',
		);
	}

	// remove htmlspecialchars'd bits
	$code = str_replace($codefind, $codereplace, $code);

	// do we have an opening <? tag?
	if (!preg_match('#^\s*<\?#si', $code))
	{
		// if not, replace leading newlines and stuff in a <?php tag and a closing tag at the end
		$code = "<?php BEGIN__VBULLETIN__CODE__SNIPPET $code \r\nEND__VBULLETIN__CODE__SNIPPET ?>";
		$addedtags = true;
	}
	else
	{
		$addedtags = false;
	}

	// highlight the string
	$oldlevel = error_reporting(0);
	if (PHP_VERSION  >= '4.2.0')
	{
		$buffer = highlight_string($code, true);
	}
	else
	{
		@ob_start();
		highlight_string($code);
		$buffer = @ob_get_contents();
		@ob_end_clean();
	}
	error_reporting($oldlevel);

	// if we added tags above, now get rid of them from the resulting string
	if ($addedtags)
	{
		$buffer = preg_replace(array(
			'#(<|&lt;)\?php( |&nbsp;)BEGIN__VBULLETIN__CODE__SNIPPET#siU',
			'#END__VBULLETIN__CODE__SNIPPET( |&nbsp;)\?(>|&gt;)#siU'
		), '', $buffer);
	}

	//$buffer = str_replace('[', '[', $buffer);

	$code = &$buffer;

	eval('$html = "' . fetch_template('bbcode_php') . '";');
	return $html;
}

.........
?>
 
Zuletzt bearbeitet:
Genau das meinte ich.

Aber ich blick da nicht richtig durch.

Die Funktion highlight_string() gibt den String str mit hervorgehobener Syntax (Syntax highlighting) aus. Dabei werden die Farben des in PHP eingebauten Syntax-Highlighter benutzt.

Und wo hin muss man den Code schreiben?

Ich bin eben
verrueckt024.gif


EDIT:
Ich hab im Internet ein Beispiel gefunden. Jetzt habe ichs Begriffen:

PHP:
<?
$phphighlight = '
<?
// eingegebener Text
   $test = "Hello World !";

// Ausgabe des Textes
   echo "$test";
?>';

   highlight_string($phphighlight);
?>
 
Zuletzt bearbeitet:
Zurück