This forum is in archive mode. You will not be able to post new content.

Author Topic: execute python code on PHP syntax  (Read 6164 times)

0 Members and 1 Guest are viewing this topic.

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
execute python code on PHP syntax
« on: December 20, 2012, 10:25:35 PM »
Does somebody know how to run python code on php syntax?
I am programmer and you are my source code

Offline geXXos

  • Royal Highness
  • ****
  • Posts: 646
  • Cookies: 178
    • View Profile
Re: execute python code on PHP syntax
« Reply #1 on: December 20, 2012, 10:47:12 PM »
Depends on what you are doing, look at this PHP extension http://www.csh.rit.edu/~jon/projects/pip/ or give a better explanation.

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: execute python code on PHP syntax
« Reply #2 on: December 20, 2012, 10:49:35 PM »
Code: [Select]
<?php exec ("python script.py"); ?>

If what you mean is execute PHP using Python syntax or vice-versa... why the fuck do you want to do so?

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: execute python code on PHP syntax
« Reply #3 on: December 21, 2012, 03:21:50 PM »
@ca0s pls watch your language, i want to made some effect on my website, but i know with python how to do, I've heard that it can do with PHP syntax (embed python code and run it)...
I am programmer and you are my source code

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: execute python code on PHP syntax
« Reply #4 on: December 22, 2012, 01:35:55 AM »
@ca0s pls watch your language
Yes, sir.

Considering the fact that you seem to not know how to code proper PHP, and believing your claiming of knowing python, your best option might be using python instead of PHP.

Note that in order to be able to embed python into PHP you will probably need to have python installed and accesible in your server, or at least some kind of library capable of doing that particular task.

Configuring your webserver to use python instead of (or even in combination with) PHP shoudn't cause much trouble to you. Ovbiously, I am assuming you have your own webserver. You probably won't be able to change a shared hosting configuration nor install packages.

I think that last option would be your better choice. Because embeding one interpreted language into another interpreted language doesn't seem very efficient for me.

I hope you are happier with this response, and that my language has not damaged your eyes and your brain this time. Have a nice day.

Regards,
ca0s
« Last Edit: December 22, 2012, 01:36:06 AM by ca0s »

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: execute python code on PHP syntax
« Reply #5 on: December 22, 2012, 04:15:09 PM »
You want to create a effect? visual? code-wise? php has almost no limitation next to python. Only python has been proved to be more powerfull in some appliances.
~Factionwars

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: execute python code on PHP syntax
« Reply #6 on: December 23, 2012, 11:09:42 PM »
i wan't to make "letter typer on screen" for example print evilzone. E after .5sec V after.5sec I... does somebody know how to do that with PHP?
I am programmer and you are my source code

Offline ajithkp560

  • /dev/null
  • *
  • Posts: 8
  • Cookies: 1
    • View Profile
    • _TERMINAL_CODER_
Re: execute python code on PHP syntax
« Reply #7 on: December 24, 2012, 06:26:44 AM »
To execute a python program

Code: [Select]
<?php echo shell_exec("python pycode.py"); ?>
or

Code: [Select]
<?php echo exec("python pycode.py"); ?>
or

Code: [Select]
<?php echo system("python pycode.py"); ?>
there are many other functions like passthru,proc_open,popen to execute commands.
« Last Edit: December 24, 2012, 06:29:35 AM by ajithkp560 »

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: execute python code on PHP syntax
« Reply #8 on: December 24, 2012, 10:59:28 AM »
i wan't to make "letter typer on screen" for example print evilzone. E after .5sec V after.5sec I... does somebody know how to do that with PHP?

You can try with flush and ob_flush. But you will get better results (and it will be easier to do) using javascript, which is executed client-side.

Offline ajithkp560

  • /dev/null
  • *
  • Posts: 8
  • Cookies: 1
    • View Profile
    • _TERMINAL_CODER_
Re: execute python code on PHP syntax
« Reply #9 on: December 24, 2012, 01:30:59 PM »
Sorry, I havent seen whats ur needing. Try code bellow.
Code: [Select]
<?php
print "E";
usleep(500000);
print 
"V";
usleep(500000);
print 
"I";
usleep(500000);
print 
"L";
?>

did you mean print this like???
PHP is the best language in web application programming.

Offline namespace7

  • Sir
  • ***
  • Posts: 561
  • Cookies: 115
  • My Brother's Keeper
    • View Profile
Re: execute python code on PHP syntax
« Reply #10 on: December 24, 2012, 02:19:43 PM »
You could write a quick PHP script to do that for any string you want.
For example you could do something like this:

Code: [Select]
<?php
$your_string 
"EvilZone";
$string_length srtlen($your_string);

for (
$i 0$i <= $string_length$i++) {
  echo 
$your_string[$i];
  
usleep(500000);
}
?>

However, whats going to happen, is the whole script is going to be executed by the server and only then will it send the generated HTML result to the client browser. So basically, even though the server will wait half a second between each letter, you will still see the string appear at the same time when the page loads. It will just take longer to load because the delay is done before the browser receives the html page from the server.

To solve this problem, you need to use ajax so that data could be loaded dynamically from the server without reloading the page. google ajax php tutorial to give you an idea. Oh and also do some reading on jQuerry. Very nice library that will make your life much easier when it comes to dynamic websites.

Now if you don't need to use PHP and don't need to have that happen in a browser, you could just write a quick Python script like this:

Code: [Select]
import sys
import time
your_string = "EvilZone\n"

for 1 in your_string:
  sys.stdout.write(1)
  sys.stdout.flush()
  time.sleep(0.5)

Note that you need to add a flush() method after write() because python by default in most installations writes all output to a buffer and sometimes it would wait for some time before outputing the stuff in the buffer to the screen (or anywhere else). And if the time it waits before outputing the buffer is higher then the time it takes to complete one iteration of the for loop, then you will see several characters appear on the screen at the same time, which is not what you want. flush() method forces python interpreter to output everything in the buffer right away without any delay.

Anyway, good luck. Coding is fun.
« Last Edit: December 24, 2012, 02:26:01 PM by namespace7 »
"A programmer’s greatest enemy isn’t the tools or the boss or the artists or the design or the legacy code or the third party code or the API or the OS. A programmer’s greatest enemy is getting stuck.
Therefore a crucial step to becoming a better programmer is learning how to avoid getting stuck, to recognize when you’re stuck, and to get unstuck." -Jeff Wofford

Offline ajithkp560

  • /dev/null
  • *
  • Posts: 8
  • Cookies: 1
    • View Profile
    • _TERMINAL_CODER_
Re: execute python code on PHP syntax
« Reply #11 on: December 24, 2012, 03:52:36 PM »
Yeah you are right. Thats rights. Javascript(or AJAX) is the better choice for this.

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: execute python code on PHP syntax
« Reply #12 on: December 26, 2012, 09:58:34 AM »
Lets just say, that is fucking stupid to do in PHP. People invented JavaScript for all the interactive front-end. PHP is just to process the data given and needed to return :)
~Factionwars

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.