Created
November 13, 2009 03:20
-
-
Save AndreasBaumgart/233560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['source'])) { | |
$source = $_POST['source']; | |
if(isset($_POST['type']) && 'php' == $_POST['type']) { | |
$code = highlight_string($source, true); | |
$output = $code; | |
} else { | |
$code = htmlentities($source); | |
$output = '<pre style="overflow: scroll; padding: 1em; background-color: black; color: white;">' | |
. $code | |
. '</pre>' . PHP_EOL; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<title>Format code samples for blogger.com</title> | |
</head> | |
<body> | |
<h1>Format code samples for blogger.com</h1> | |
<p> | |
It's been a little annoying to paste code samples on blogger.com blogs. The | |
built-in WYSIWYG (WYSIWTF?) editor isn't very friendly to programmers.<br/> | |
So, here's the solution: Paste your code sample here, press the button and | |
copy the result into the HTML-Code-View of your blog post. | |
</p> | |
<form action="" method="post"> | |
<textarea name="source" id="Source" style="height: 200px; width: 47%; margin-right: 5%;"> | |
<?php if(isset($source)): ?><?php echo htmlentities($source); ?><?php else: ?> | |
<?php | |
phpinfo(); | |
?> | |
<?php endif;?> | |
</textarea> | |
<textarea name="output" id="Output" style="height: 200px; width: 47%;;"> | |
<?php if(isset($output)): ?><?php echo htmlentities($output); ?><?php endif;?> | |
</textarea> | |
<div style="text-align: center; margin: 1em auto 0 auto;"> | |
<input <?php if(isset($_POST['type']) && 'php' == $_POST['type']): ?>checked="checked"<?php endif;?> type="radio" name="type" value="php" />PHP code | |
<input <?php if(!isset($_POST['type']) || 'php' != $_POST['type']): ?>checked="checked"<?php endif;?> type="radio" name="type" value="generic" /> Arbitrary code | |
</div> | |
<br/> | |
<div style="margin: 1em auto 0 auto; width: 20%;"> | |
<input type="submit" value=">> Convert >>" style="width: 100%;" /> | |
</div> | |
</form> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to write code