Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a function in file background.py

#! /usr/bin/python
import sqlite3
db = sqlite3.connect("vt.db")
cr=db.cursor()
def content():
icerik =""
sql_sorgusu= db.execute("SELECT * FROM icerik").fetchall()
if len(sql_sorgusu = 0):
    print("")
else:
    icerik +="""
            <div class="article"><img src='""" + str(i[3]) + """' alt="Bili?im Hukuku" class="img"><a href="" class="categori">Bili?im Hukuku</a><br><h3 class="articleh3">""" + str(i[1])+ """</h3><a href='/blog.html?id=""" + str(i[0])+ """'>Devam?n? oku</a></div>
    """
return icerik

and i want the run this function in my php file. I know the command shell_exec and exec but they are not running the function or idk how to do that can somebody help me.

question from:https://stackoverflow.com/questions/65940739/can-i-run-python-function-in-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
84 views
Welcome To Ask or Share your Answers For Others

1 Answer

I don't know how to embed Python code in PHP this python code


#! /usr/bin/python
import sqlite3

db = sqlite3.connect("vt.db")
cr = db.cursor()

icerik = ""
sql_sorgusu = db.execute("SELECT * FROM icerik").fetchall()

for i in sql_sorgusu:
    if len(i) >= 1:
        icerik += f"""
        <div class="article">
            <img src='+ {str(i[3])}' alt="Bili?im Hukuku" class="img">
            <a href="" class="categori">Bili?im Hukuku</a>
            <br>
            <h3 class="articleh3"> {str(i[1])}</h3>
            <a href='/blog.html?id= {str(i[0])}'>Devam?n? oku</a>
        </div>
        """
    else:
        print("not SQL match !")

print(icerik) # complete html code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...