• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to integrate Python with PHP?

#1
I understand many websites use PHP together with Python but I doubt if they also use CodeIgniter.

I want a language that will facilitate what PHP cant do.

Does anybody know how to integrate Python with PHP?

I would like interaction similar to HTML.
Reply

#2
What do you want to do with python what you cant do in PHP?
Codeigniter are made with PHP, so anything you can do in PHP you can do in Codeigniter.

The only way to execute something outside PHP are with these function.
https://www.php.net/manual/en/function.e...ellcmd.php
https://www.php.net/manual/en/function.shell-exec.php
https://www.php.net/manual/en/function.exec.php
Reply

#3
(01-18-2020, 03:43 PM)jreklund Wrote: What do you want to do with python what you cant do in PHP?
Codeigniter are made with PHP, so anything you can do in PHP you can do in Codeigniter.

The only way to execute something outside PHP are with these function.
https://www.php.net/manual/en/function.e...ellcmd.php
https://www.php.net/manual/en/function.shell-exec.php
https://www.php.net/manual/en/function.exec.php

Thanks for those links I need to study them.

When using fwrite & particularly fseek in PHP it overwrites data that is ahead so the only mode that is usable is "a" which starts at the end of file and appends, which creates recent at the bottom, whereas I prefer recent at the top.

And now I find PHP does not facilitate backspace \b in fwrite.

I'm open to ideas on how I can stick with just one language.
Reply

#4
The only way I know are to read the content of the file. Append your new data at the beginning and saving it again.

Depending on what you are doing with the file (parsing?) you can reverse it (after it have been read) with PHP if you want the end at the beginning.

What does \b do? Never used it.
Reply

#5
(01-19-2020, 05:08 AM)jreklund Wrote: The only way I know are to read the content of the file. Append your new data at the beginning and saving it again.

Depending on what you are doing with the file (parsing?) you can reverse it (after it have been read) with PHP if you want the end at the beginning.

What does \b do? Never used it.

Anything done with fwrite from the beginning has the problem with overwriting any text that is ahead so appending from the end as "a" does, avoids that overwriting. I would like to know how to "reverse it after it has been read". But I'm not sure if you & I are thinking of the same function. It is the last message that I want at the top, not end at the beginning. I should get the last message at the top by using fseek & fwrite but the overwriting makes that impossible.

Apparently backspace \b works in other languages & I assume includes Python, but it doesn't work in PHP. Backspace \b is similar to Newline \n.
Reply

#6
What a horrible and crazy idea, mixing php and python. Why would you want to create a mess like that? Choose one or the other. Sometimes languages don't do things other languages do, but there are always ways around these sorts of limitations. Think out side the box, use substr(), trim(), etc for "backspace", write your own prepend function. Heck, just Google "prepend file" in php and you will find plenty of solutions.
Reply

#7
(01-19-2020, 08:31 AM)eggbert Wrote: What a horrible and crazy idea, mixing php and python.  Why would you want to create a mess like that?  Choose one or the other.  Sometimes languages don't do things other languages do, but there are always ways around these sorts of limitations.  Think out side the box, use substr(), trim(), etc for "backspace",  write your own prepend function.  Heck, just Google "prepend file" in php and you will find plenty of solutions.

@eggbert I like constructive criticism but comments like "horrible and crazy idea" - "create a mess like that" - "think out side the box" are not constructive. You could have been more elaborate in your comments which would be constructive.

Before I post these questions I spend sometimes several days Googling to find an answer as I have already Googled "prepend file" in php, with little results however I haven't finished investigating those results.

Did you know Facebook uses PHP as a base and many other languages including Python? If PHP was adequate for Facebook there would be no need for that corporate to use other languages.

If I get too involved with Python I may end up ditching PHP, but I've spent several years already with PHP and finding it in places inadequate.
Reply

#8
@christaliise: You can't do it like you want. You will need to read the entire file into memory and append the new data at the beginning and saving it again.

$a = file_get_contents('filename.txt');
$b = 'New information' . $a;
file_put_contents('filename.txt', $b);

Regarding the reverse part, it depends on what you are storing. Can it be parsed and stored in an array?
https://www.php.net/manual/en/function.a...everse.php

And as you can't do this in PHP. Don't do it. It will give you problems down the road. So live with the limitation and redesign your application.
Reply

#9
(01-19-2020, 10:03 AM)christaliise Wrote:
(01-19-2020, 08:31 AM)eggbert Wrote: What a horrible and crazy idea, mixing php and python.  Why would you want to create a mess like that?  Choose one or the other.  Sometimes languages don't do things other languages do, but there are always ways around these sorts of limitations.  Think out side the box, use substr(), trim(), etc for "backspace",  write your own prepend function.  Heck, just Google "prepend file" in php and you will find plenty of solutions.

@eggbert I like constructive criticism but comments like "horrible and crazy idea" - "create a mess like that" - "think out side the box" are not constructive. You could have been more elaborate in your comments which would be constructive.

Before I post these questions I spend sometimes several days Googling to find an answer as I have already Googled "prepend file" in php, with little results however I haven't finished investigating those results.

Did you know Facebook uses PHP as a base and many other languages including Python? If PHP was adequate for Facebook there would be no need for that corporate to use other languages.

If I get too involved with Python I may end up ditching PHP, but I've spent several years already with PHP and finding it in places inadequate.


Oh, get over yourself.  Yes, I would assume facebook probably uses many different technologies for many different things, though I highly doubt they mix and match them based on which is easier to do mundane thing such as prepending files.  What are you going to do, use python to prepend files, and PHP for everything else? Sorry, but that's a mess (not to mention a horrible idea),  and makes me wonder if you're posting here to amuse yourself by pointing out PHP's (supposed) limitations, or something silly like that.
Reply

#10
(01-19-2020, 01:12 PM)eggbert Wrote: What a horrible and crazy idea, mixing php and python.  Why would you want to create a mess like that? 
...
Oh, get over yourself.  Yes, I would assume facebook probably uses many different technologies for many different things, though I highly doubt they mix and match them based on which is easier to do mundane thing such as prepending files.  What are you going to do, use python to prepend files, and PHP for everything else? Sorry, but that's a mess (not to mention a horrible idea),  and makes me wonder if you're posting here to amuse yourself by pointing out PHP's (supposed) limitations, or something silly like that.

Thank you, I couldn't have said it better!  Big Grin
Test your translation files with Translation Tester
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.