Php to html python

Php to html python

I need some help on how to pass a value in python to my HTML page using php WITHOUT intercepting my CSS design that i created.
Here’s my HTML code:

 

Get data from the Sound Sensor !



By clicking 'Get Data', you have agree to let Audio Sense record the sound environment of your surrounding and also your voice.

import RPi.GPIO as GPIO, time,os GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) def RCtime(Pipin): measurement = 0 GPIO.setup(Pipin, GPIO.OUT) GPIO.output(Pipin, GPIO.LOW) time.sleep(0.1) GPIO.setup(Pipin, GPIO.IN) while(GPIO.input(Pipin) == GPIO.HIGH): measurement = measurement + 1 loudness = (measurement *3.3)/1024 #loudness = ((measurement -40000)* 3.3)/1024 return loudness while True: loudness = RCtime(18) print 'The reading is', loudness time.sleep(0.2) 

I am using GPIO 18.
Sorry, i am not a pro or a amateur in programming. But was asked to do this task.
Really thank you for helping me.

Re: Reading Value from python using php to HTML

1) where is PHP? (or «why do you think you need php?»)
2) what are you trying to do? pass ONE value or pass multiple values (i see a short sleep)
3) is it clear that you’ll record the loudness of the server and not of the client?

1) is the PY script working if run from a command line?
2) is the py script working if run from a web browser?

Re: Reading Value from python using php to HTML

1) where is PHP? (or «why do you think you need php?»)
2) what are you trying to do? pass ONE value or pass multiple values (i see a short sleep)
3) is it clear that you’ll record the loudness of the server and not of the client?

1) is the PY script working if run from a command line?
2) is the py script working if run from a web browser?

1) I do not whether i need a php actually, if i could pass the value from python to HTML would be the best i guess?
2) I am trying to pass 1 value, but it would be good if i am able to have the knowledge of passing multiple values.
3) I guess it’s on the server side ? Because i am hosting my webserver on my raspberry pi instead on the other computer.
because previously i tried to host my webserver on my other computer and using the raspberry pi just to sense the audio frequency .

1) The py script is working on command line.
2) I am not sure how to run on web browser .
Cause i got no knowledge on how to do programming or so.

Re: Reading Value from python using php to HTML

well, this is not «some help»

understand what CGI can serve your webserver. if it can server python files, it’s a step less to do.
change your python script to print only one value (otherwise it will run forever and this is not what we want)
if you want to get the value without reloading the page, you have to learn also a little of javascript (i strongly suggest jquery)

with jquery you can also read a value every x seconds.

Читайте также:  Javascript как сделать переменную глобальной

Then if you really want to do something advanced, you can learn websockets, but this is really far ahead

btw, to answer your question, you can use php in this way to read output from a py script (like every other executable)

 $tPieces = Array(); $result = ""; exec("something.py 2>&1", $tPieces, $result); //return if($result > 0) < //error returned print("Need to manage error") >else < //good, can work on tPieces array print("You can read output in tPieces array"); >

Re: Reading Value from python using php to HTML

Massi wrote: well, this is not «some help»

understand what CGI can serve your webserver. if it can server python files, it’s a step less to do.
change your python script to print only one value (otherwise it will run forever and this is not what we want)
if you want to get the value without reloading the page, you have to learn also a little of javascript (i strongly suggest jquery)

with jquery you can also read a value every x seconds.

Then if you really want to do something advanced, you can learn websockets, but this is really far ahead

btw, to answer your question, you can use php in this way to read output from a py script (like every other executable)

 $tPieces = Array(); $result = ""; exec("something.py 2>&1", $tPieces, $result); //return if($result > 0) < //error returned print("Need to manage error") >else < //good, can work on tPieces array print("You can read output in tPieces array"); >

I guess for now, what i need to do is to read the value for once will do :X Cause i am new so i can’t understand it so much about it.

 exec("something.py ", $loudness, $result);

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

neurobin/php2html

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This is a simple script/tool written in python (3.4) to convert PHP scripts to static HTML pages. The goal is to convert an entire PHP website residing in localhost to a static HTML website altogether. This conversion can be done on a directory containing a website as well as on a single PHP script.

The system on which this tool will be run, must have PHP installed. It executes every PHP script with the system PHP (CLI) environment and parses the output to replace markups as required and produces .html for each .php .

The script can be run without installing if python3.4 is available:

The tool can be installed by running the install file provided, in any Linux System:

chmod +x install sudo ./install #Must be run within the package directory (with `./` at the beginning)

Or just copy the php2html script to /usr/bin

Читайте также:  Birthday Reminders for August

For windows, You can rename the file with a .py extension and run it within python environment. Or you can use cxfreeze to make a binary build for standalone executable. I may not provide any binary build of this tool anymore.

Both Windows and Linux versions of this tool can be used the same way (In windows make sure to add the executable path in the PATH environment variable). It can be run with cmd in windows and with terminal emulator in Linux.

php2html phpscript.php php2html . destination_directory # This will convert entire site in current directory to html

Always run this command from within the Document Root of your website ( public_html or www or whatever it is), otherwise unexpected results might occur.

Usage: php2html src dest [options]

options: src dest -q -h —help -o -i -v —version -a.htaccess -rd

src : the source path. src can not be a directory other than current directory, to pass current directory as src, either use . or ./

dest : the destination directory.

-q : means quite (won’t print any output other than errors) -q : can be placed anywhere in the argument sequence.

-h : shows this help menu —help : shows this help menu

-o : overwrites destination directory This mode is not dependent on the existance of destination directory

-i : is a dangerous option and should be avoided This replaces all the PHP files to resulting HTML file in the source directory. This doesn’t require the option dest, neither it will prompt for it, and if dest is given as command line argument, it will simply ignore that

-v : shows version information —version : shows version info

-a.htaccess : processes the .htaccess file. Other access file can be processed by changing the .htaccess part to the actual name of the used AccessFile. There must not be any white space between -a and .htaccess If you pass only -a, it will neither look for any AccessFile and nor it will try to process them. If you don’t pass -a as an option, it will look for .htaccess file by default

-rd : reserve Directory Structure. By default empty directory will not be copied to the destination directory. If -rd is specified, empty directory will also be copied to the destination to preserve directory structure

-ed : Exclude directory. The directory passed with this options won’t be included in new html site.

-ef : Exclude file. The file specified by this option won’t be included in new html site.

Example: php2html php2html . dest # . is the current dir php2html -q src.php dest php2html src.php -q dest php2html src.php dest -q php2html src.php dest -q -o # This and above takes .htaccess by default as the access file php2html src.php dest -q -o -a # This one ignores any accessfile php2html src.php dest -q -o -a.config # This one takes .config as AccessFile 
  1. This tool only changes the relative PHP URLs to HTML URLs, no absolute URL is changed in any ways.
  2. It’s recommended that you use JavaScript ( window.location.href or such) to get the current location not PHP ( $_SERVER[‘PHP_SELF’] ), if you are gonna use that URL in any link which you need to be converted to html link, otherwise it may produce unexpected results.
  3. If you want to use PHP variables: $_SERVER[‘PHP_SELF’] or $_SERVER[‘DOCUMENT_ROOT’] see the tips & tricks section.
  4. Use relative URL path as much as you can. If any relative URL is specified with absolute path (with http:// or www .), it will be ignored and won’t be converted to HTML URL path.
Читайте также:  Формула линейной интерполяции python

If you want to use $_SERVER[‘PHP_SELF’] or $_SERVER[‘DOCUMENT_ROOT’] in a page, add the following lines at the top of the page:

 else <$__RDOCROOT=preg_replace($pat,'../',$__CURDIR);$__CURDIR.="/";>$__CURDIR = $__RDOCROOT . $__CURDIR; $__SELF=$__CURDIR.$__SELF; //$__RDOCROOT and $__CURDIR contains a / at end. It's necessary ?> 
  1. Now you can use $__RDOCROOT or $GLOBALS[‘__RDOCROOT’] (inside a funcion, class or namespace) in place of $_SERVER[‘DOCUMENT_ROOT’] .
  2. $__CURDIR or $GLOBALS[‘__CURDIR’] (inside a funcion, class or namespace) in place of getcwd() or current directory.
  3. $__SELF or $GLOBALS[‘__SELF’] (inside a funcion, class or namespace) in place of $_SERVER[‘PHP_SELF’] .

All these new variables are relative paths not absolute ones.

This project emerged from personal needs. I liked to write webpages with PHP and host most of my project related pages on github while was not particularly interested on using Jekyll. That was the reason I wrote this script in the first place, to do the conversion from PHP to HTML. So this may not meet the needs of most of the PHP web developers out there.

It comes with a copy of GPL v3 License with no warranty of any kind, so use with care.

If you are a developer, you can consider contributing to this project by forking this repository and making changes for better and do a pull request, or sharing ideas and suggestions or finding bugs, anything at all, what you think will be beneficial for this project.

If you aren’t a developer, but still want to contribute, then you can support the contributing developers spiritually, by starring the repository and sharing ideas. If you want to be notified of the continuous development, you can add this in your watch list in Github.

If you find any problems or bugs please open an issue here

Источник

PHP to Python

This online converter allows to convert PHP to Python.

This tool allows to quickly see the correspondence of PHP code in Python language.The generated code may be wrong, it must be reworked before using it.New PHP8 features/syntaxes are not supported.

User guide

  • First, fill in the PHP editor. You can Drag and drop your PHP source file, copy and paste your source code, or type directly into the PHP editor.
  • Click on «Convert» button to convert your PHP code to Python.
  • You can get your Python source code by clicking on the «Download file» or «Copy to clipboard» buttons.

PHP to Python compiler

This tool is nice when you have a piece of PHP code to convert to Python. In one click, you get the correspondence in this language.

It can also be useful when you have to write a script in Python but you do not know this language. By having knowledge of PHP, you write the script in this language and you obtain the Python code.

One of the use cases is discovering the Python language. You write a piece of PP code (a conditional structure, a loop etc.) and you discover how it is written in Python.

You can enter PHP 7 code (PHP 8 is not supported). The code is converted to Python 3.

You can report a bug or give feedback by adding a comment (below) or by clicking «Contact me» link (at the top right hand corner of the page).

Enter the code (case insensitive) *

If you can not read the code, click here to generate a new code

Источник

Оцените статью