My python code gets data from php it takes value in text_content variable and then execute its script. But i dont understand to how to return back the results to php. help me please.
<body>
<?php
// define variables and set to empty values
$text_content="";
$hello="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$hello = $_POST['text_content'];
$command="\Users\jonii\AppData\Local\Programs\Python\Python35\python splitter.py $hello ";
exec($command , $out,$ret );
//echo $out;
echo $ret;
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<textarea name="text_content" value="<?php echo $text_content;?>" cols="40" rows="4"> </textarea>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
my python file is:
#!/Users/jonii/AppData/Local/Programs/Python/Python35/python
# Import modules for CGI handling
import cgi, cgitb
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
import sys
print("Content-type:text/html\n")
print("hello")
text_content = ''
for word in sys.argv[1:]:
text_content += word + ' '
print(text_content)
def sentence_split( text_content ):
# Add both the parameters and return them."
print(sent_tokenize(text_content))
return
# Now you can call sentence_split function
sentence_split( text_content );
echo $out;, but$outdoes contain your data. However, it's as an array, and not a string. Is that what you saw? Just the textArray?