Files
script_dev/hensu.py

25 lines
684 B
Python

import chardet
import re
def detect_encoding(file_path):
with open(file_path, 'rb') as f:
raw_data = f.read()
result = chardet.detect(raw_data)
return result['encoding']
def extract_php_variables(file_path):
encoding = detect_encoding(file_path)
with open(file_path, 'r', encoding=encoding) as f:
content = f.read()
variables = re.findall(r'\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*', content)
unique_vars = sorted(set(variables))
return unique_vars
# 使用例
php_file = 'OfficeChusenTourakuKakutei.php'
variables = extract_php_variables(php_file)
print("PHPファイル内の変数一覧:")
for var in variables:
print(var)