Skip to content

Instantly share code, notes, and snippets.

@jnlin
Last active August 29, 2015 14:17
Show Gist options
  • Save jnlin/2bbf8155e8f97337e7d5 to your computer and use it in GitHub Desktop.
Save jnlin/2bbf8155e8f97337e7d5 to your computer and use it in GitHub Desktop.
<?php
function toMingKuoYear1($matches)
{
$year = $matches[1];
$year = $year - 1911;
return " title='$year年'";
}
function toMingKuoYear2($matches)
{
$year = $matches[1];
$year = $year - 1911;
return " $year年 ";
}
function toMingKuoYear3($matches)
{
$year = $matches[1];
$year = $year - 1911;
return ">$1年</a>";
}
$link_html = preg_replace_callback("/ title='([\d]{4})'/", toMingKuoYear1, $link_html);
$link_html = preg_replace_callback("/ ([\d]{4}) /", toMingKuoYear2, $link_html);
$link_html = preg_replace_callback("/>([\d]{4})<\/a>/", toMingKuoYear3, $link_html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment