Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created April 29, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save violetyk/8424de43362dd8823252b8c63aeefa2c to your computer and use it in GitHub Desktop.
Save violetyk/8424de43362dd8823252b8c63aeefa2c to your computer and use it in GitHub Desktop.
<?php
$data = '';
$list = array();
if (!empty($_POST['data'])) {
$data = $_POST['data'];
$matches = array();
$result = preg_match_all("/u'(.*)',|'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})',/", $data, $matches);
if ($result) {
$subjects = $matches[1];
$subjects[0] = array_filter($matches[2])[0];
foreach ($subjects as $subject) {
$decoded = preg_replace_callback('|\\\\u([0-9a-f]{4})|i', function($matched){ return mb_convert_encoding(pack('H*', $matched[1]), 'UTF-8', 'UTF-16'); }, $subject);
$list[] = sprintf("%s\n", str_replace('\n', '<br>', $decoded));
}
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>decode python exception</title>
</head>
<body>
<h1>decode python exception</h1>
<div>
<form method="post">
<textarea id="" name="data" cols="30" rows="10"><?php echo $data ?></textarea>
<input type="submit">
</form>
</div>
<div>
<?php if (!empty($list)): ?>
<ol>
<?php foreach ($list as $v): ?>
<li><?php echo $v; ?></li>
<?php endforeach ?>
</ol>
<?php endif; ?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment