スクリプトファイルを追加
This commit is contained in:
24
hensu.py
Normal file
24
hensu.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user