PHP - Rgarding Python And Php
HEllo,
I want to know how can i run python script from PHP? an small example would be sppreciated so i' can get an idea... Similar Tutorialsi want to convert a website from php to python . please tell me how i can do that . thanks Hello please i need some help to rewrite this code in PHP to Python i am totally new in this and need this baddly please help if u can. Thanks a lot.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>phpChart - Basic Chart</title> </head> <body> <?php function array_delete($array, $element) { return array_diff($array, $element); } $firs_constant = 0.005; $secound_constant = 0.005; $rozdielne[1000] = 0; $link = mysqli_connect('127.0.0.1', 'webmaster', 'noerroronweb',"smart_meter"); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysqli_query($link,"SELECT date, current3 FROM `current` ORDER BY `current`.`date` ASC"); $values = array(); $i=0; echo "<br>"; $y=0; while($row[$i++] = mysqli_fetch_array($result)) { if($row[$i-1]['current3'] == "0") $row[$i--]; } for($z=0;$z<=$i; $z++){ $rozdiel = $row[$z]['current3'] - $row[$z+1]['current3'] ; if(abs($rozdiel)>=$firs_constant){ $rozdelove[$y] = abs($rozdiel); $y++; } } echo "<h1>Vypis rozelnych hodnot</h1><br>"; $p=0; for($z=0;$z<=$y; $z++){ $je=false; for($m=$z-1;$m>=0; $m--){ $min = $rozdelove[$m]- $secound_constant; $max = $rozdelove[$m]+ $secound_constant; if($rozdelove[$z]<= $max && $rozdelove[$z]>= $min ) $je=true; } if($je == false ){ $je=false; array_push($rozdielne,$z); $p++; } } for($m=0;$m<count($rozdelove);$m++){ for($k=0;$k<count($rozdelove);$k++){ if ($m!=$k){ $sucet = $rozdelove[$k] + $rozdelove[$m]; foreach ($rozdielne as &$value) { if($sucet == $rozdelove[$value]){ echo "Toto je sucet: ".$rozdelove[$value]."<br>"; echo "Pre hodnoty: ".$rozdelove[$k]."a ". $rozdelove[$m] ."<br>"; } } } } } echo "<pre>"; var_dump($rozdielne); echo "</pre>"; ?> </body> </html> Edited by skusobny, 19 May 2014 - 09:41 PM. So I just started watching the videos from Stanford, Google, MIT and a few on youtube. One of them contained the code for using tkinter function to create an application window and I tried to put the same type of thing together can anyone tell me what I am doing wrong cause nothing is happeing for me. I am running linux mint:
# - So this is what it feels like # - To be alive #!/user/bin/python import sys author = "Brian T. Flores" version = "0.1" sessionID = 0 #Get Interface from Tkinter import * #initialize interface root = Tk() #modify root window info root.title("Unknown Limits - Massive Multiplayer RPG") root.geometry("200x100") #initialize root window root.mainloop() #if session is > 0: #Get Player Info UserName = "Brian Flores" Password = "enterprise" rank = 32 #planetOverview planetName = "Earth" plasmaOnhand = 1000000000 titainiumOnhand = 340000 crystalOnhand = 55000000 magneticEnergyOnhand = 350000 ecosystem = "No" # yes or no depending on wars or natural disasters that could have damaged or destroyed your ecosystem if there is no ecosystem the atmosphere must be cleaned up and another must be transplanted from another world. ecosystemDamage = 10000; #Damage can result from experiments, wars, natural disasters. At 10,000 damage the ecosystem goes extinct. You can repair this damage my researching technologies and building machines to do such repair # else: # print "You are not logged in!"; # raw_input()Well for some reason it's not working. All I am doing here is setting some vars and using the root.tk function. If anyone has any Ideas or tips to get this basic script working let me know. Thank you, DaRedHead Edited by DaRedHead, 21 November 2014 - 09:17 PM. I am a bit desperate about this problem that I have been trying to solve for several days now. I'm trying to run a Python script from the exec() function in php. The script is called but the print job is never executed. This process has been running for several years and for no clear reason it suddenly stopped working. On my home computer, it works without any problem. In my virtual machine, nothing happens. The print() functions present in the script are well displayed by the return value received by php but the printing is not executed. The virtual machine is a test environment, in production it is also an physical machine. PHP <?php exec("py C:\xampp\htdocs\test\test.py", $out, $res); echo "<pre>"; print_r($out); echo "</pre>"; echo "<pre>"; print_r($res); echo "</pre>"; ?>
if __name__ == "__main__": try: filename = "C:/xampp/htdocs/test/test.pdf" win32api.ShellExecute(0, "print", filename, None, ".", 0) except Exception as e: print(f "An error occured during print_pdf : {e}")
The two environments are approximately the same: I'd like to point out that running the script directly from the CLI works on both machines. On the problematic machine, exec() only returns the result of print(..) I already opened a thread a few months ago about this problem but received no response.
Thank you in advance. |