Skip to content

Instantly share code, notes, and snippets.

@AndreasBaumgart
Created November 13, 2009 03:20
Show Gist options
  • Save AndreasBaumgart/233560 to your computer and use it in GitHub Desktop.
Save AndreasBaumgart/233560 to your computer and use it in GitHub Desktop.
<?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: ?>
&lt;?php
phpinfo();
?&gt;
<?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="&gt;&gt; Convert &gt;&gt;" style="width: 100%;" />
</div>
</form>
</body>
</html>
@anjandk
Copy link

anjandk commented Jan 5, 2020

how to write code

@kicktv
Copy link

kicktv commented May 29, 2023

very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment