User: Rewrite this code to PHP. Write only code, without Markdown:
const path = require('node:path');
const fs = require('node:fs');

// 从php代码翻译而来
function titleToFileBaseName($title) {
  var $name = $title;
  // 文件名中的短横线出现了3种情况: "－","—","-"
  // 最好是为每个作者生成1个标题与文件名的对照表txt文件
  $name = $name.replace(/“(.*?)”/g, '「$1」');
  $name = $name.replace(/"(.*?)"/g, '「$1」');
  $name = $name.replace(/'(.*?)'/g, '「$1」');
  $name = $name.replace(/-{2,}/g, '——');
  $name = $name.replace(/\.{3,}/g, '…');
  $name = $name.replace(/\.{2,}/g, '');
  $name = $name.replace(/</g, '〈');
  $name = $name.replace(/>/g, '〉');
  // 半角标点符号转全角
  // $name = str_replace(
  //   ['[',']','*','~','`','(',')','#','$','!',',','/','\\','&','+','?',':','<','>'],
  //   ['［','］','＊','～','～','（','）','＃','＄','！','，','／','＼','＆','＋','？','：','〈','〉'],
  //   $name
  // );
  // 半角标点符号转全角
  // https://zh.wikipedia.org/wiki/ASCII
  // https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block)
  $name = $name.replace(/[\x21-\x7E]/g, function ($char) {
    if (!/\w/.test($char)) {
      return String.fromCharCode($char.charCodeAt(0) + 0xFEE0);
    }
    return $char;
  });
  // $name = $name.replace(/[\^\/<>"\':;?|* ]+/g, ' ', $name);
  $name = $name.replace(/([A-Z])＇/gi, '$1\'', $name); // 英文后面的单引号
  $name = $name.replace(/([A-Z])－([A-Z])/gi, '$1-$2', $name); // 英文字母间的连字符(-)
  $name = $name.replace(/．/g, '。', $name);
  $name = $name.replace(/～+/g, ' ');
  $name = $name.replace(/[，。·｀～\s]+$/g, '', $name); // 删掉末尾逗号句号
  $name = $name.replace(/\s\s+/g, ' ');
  $name = $name.trim();
  return $name;
}

const dataDir = process.argv.includes('--dataDir') && process.argv[process.argv.indexOf('--dataDir') + 1] || path.resolve(__dirname, '../ecl');
const author = process.argv.includes('--author') && process.argv[process.argv.indexOf('--author') + 1] || '沙琪儿';
const readmeFile = `${dataDir}/${author}/README.md`;
const readmeUseFile = `${dataDir}/${author}/README-USE.md`;
const readmeFileReal = fs.existsSync(readmeUseFile) ? readmeUseFile : readmeFile;
const datefile = `${dataDir}/${author}/README-date.md`;

if (!fs.existsSync(readmeFileReal)) {
  console.log('file not found: ' + readmeFileReal);
  process.exit();
}

const readmeContent = fs.readFileSync(readmeFileReal, 'utf8').replace(/\r\n/g, '\n');

let chapter = '';
let missingCount = 0;
let dateLines = [];
readmeContent.split('\n').forEach(line => {
	if (line.startsWith('- ')) {
		let isChapter = true;
		chapter = line.slice(2).trim();
		if (!fs.existsSync(`${dataDir}/${author}/${chapter}`)) {
			line += ' (missing)';
			chapter = '';
		}
	} else if (chapter && line.startsWith('  - ')) {
		let isArticle = true;
		let title = line.slice(4).trim();
		let fileBaseName = titleToFileBaseName(title);
		let articleFile = `${dataDir}/${author}/${chapter}/${fileBaseName}.md`;
		if (!fs.existsSync(articleFile)) {
			line += ' (missing)';
			missingCount++;
		} else {
			let articleFileContent = fs.readFileSync(articleFile, 'utf8').replace(/\r\n/g, '\n');
			let m = articleFileContent.match(/^- 日期: (\d+[\/\-]\d+[\/\-]\d+)/m)?.[1];
			if (m) {
				let date = m.replace(/[\/\-](\d)(?!\d)/g, '\/0$1');
				line = `  - ${date} ${title}`;
			}
		}
	} else {
	}
  dateLines.push(line);
});
let dateContent = dateLines.join('\n');
dateContent = dateContent.replace(/(\n  - [^\n]+)+/g, re=>{
  return re.split('\n').sort().join('\n');
});
fs.writeFileSync(datefile, dateContent, 'utf8');
console.log('write to file: ' + datefile);
console.log('missing count: ' + missingCount);

User: Translate code
Assistant: