EvilZone
Programming and Scripting => Web Oriented Coding => : Ethereal December 20, 2012, 10:25:35 PM
-
Does somebody know how to run python code on php syntax?
-
Depends on what you are doing, look at this PHP extension http://www.csh.rit.edu/~jon/projects/pip/ or give a better explanation.
-
<?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?
-
@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)...
-
@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
-
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.
-
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?
-
To execute a python program
<?php echo shell_exec("python pycode.py"); ?>
or
<?php echo exec("python pycode.py"); ?>
or
<?php echo system("python pycode.py"); ?>
there are many other functions like passthru,proc_open,popen to execute commands.
-
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.
-
Sorry, I havent seen whats ur needing. Try code bellow.
<?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.
-
You could write a quick PHP script to do that for any string you want.
For example you could do something like this:
<?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:
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.
-
Yeah you are right. Thats rights. Javascript(or AJAX) is the better choice for this.
-
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 :)