So I am making a search engine to search the internet and the engine is powered with python and the webpage for the results is in php. I need to take variables (namely, the filelist list) and return them to the php script. Please excuse any typos.
<html>
<head>
<script src='searchengine.js' type='text/javascript'></script>
</head>
<body>
<?php
$cmd='python3 searchresult.py'+$_POST["searchquery"];
$output = shell_exec($cmd);
echo $output;
?>
</body>
</html>
is the php code.
import sys
from os import listdir, basename
import re
keyword=sys.argv[1]
keyword=str(keyword)
filelist=[]
db='C:\\Users\\monik\\Documents\\searchengine\\db'
filestoparse=listdir(db)
for file in filestoparse:
with open(file, 'r') as f:
filecontent=str(f.read)
result=re.findall(keyword, filecontent)
if len(result)>=5:
filelist.append(basename(f.name))
is the python code.