Jump to content

Lassie

Members
  • Content Count

    390
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Lassie

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thanks guys, I now have it working as required.
  2. Could you expand on your comments please. If on calling the function I do this: is is_connected($connection) //and funtion is_connected($connection) I still don’t get a value. ?
  3. I have a function that needs to return a value and it isn’t.I think it’s a scope issue but can’t solve it. The function is function is_connected() { $addr= 'www.google.com'; if (!$socket = @fsockopen($addr, 80, $num, $error, 5)){ $connection = 0; }else { $connection = 1; { return $connection; } is_connected() echo $connection; The function works, but I do get a warning $connection not defined and I don’t get a value. Any help appreciated.
  4. Yes you are right it is how to run the python script from a php script that happens to be a wordpress web pgae running on an apache server. Yes I have tried googling and my latest effort is $command = escapeshellcmd('/home/pi/sense-test.py'); $output = shell_exec($command); echo $output; I get no output. I have checked permissions to make it executable. My thinking now is to move the file to the Apache folder and work from there.
  5. Please note this should be titled run PYTHON script from php webpage Apologies
  6. I need to execute a python program called from inside a php web page. the web page runs without errors and the python script will run from a terminal but the two together dont dance. Any help would be welcome. php <?php /* * Template Name:message * * */ ?> <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the page. * If you want to overload this in a child theme then include a file * called loop-page.php and that will be used instead. */ get_template_part( 'loop', 'page' ); //get message //print_r($_GET); //echo "<br />"; //$message= $_GET['message']; Will be appened to $command $command= "/home/pi/sense-test.py"; exec($command); echo $message; echo "<br />"; echo "Message Recieved"; echo "The time is" . date9"h:i:sa"); ?> </div> </div> <?php get_footer(); ?> Python #!/usr/bin/env python3 from sense_hat import SenseHat sense = SenseHat() sense.show_message("Hello World")
  7. Thanks for confirming that. Being a pensioner, your first option is the way i will go.
  8. I want to convert a program from what I think is Ruby to PHP as I have no knowledge of Ruby. Could someone confirm if the posted code is Ruby please and if there are any known methods to help with a conversion. Is it possible to run Ruby code within PHP? The background to this request is that I have a 3 axis accelerometer and would like to construct a pedometer. I have the data logged to a file but coding the pedometer is a challenge. I found the following ,A Pedometer in the Real World Dessy Daskalov' which does what I want but I dont follow the code. For those interested a link to the article:-http://www.aosabook.org/en/500L/a-pedometer-in-the-real-world.html Any guidance appreciated and I hope this is the right forum. class Parser attr_reader :parsed_data def self.run(data) parser = Parser.new(data) parser.parse parser end def initialize(data) @data = data end def parse @parsed_data = @data.to_s.split(';').map { |x| x.split('|') } .map { |x| x.map { |x| x.split(',').map(&:to_f) } } unless @parsed_data.map { |x| x.map(&:length).uniq }.uniq == [[3]] raise 'Bad Input. Ensure data is properly formatted.' end if @parsed_data.first.count == 1 filtered_accl = @parsed_data.map(&:flatten).transpose.map do |total_accl| grav = Filter.low_0_hz(total_accl) user = total_accl.zip(grav).map { |a, b| a - b } [user, grav] end @parsed_data = @parsed_data.length.times.map do |i| user = filtered_accl.map(&:first).map { |elem| elem[i] } grav = filtered_accl.map(&:last).map { |elem| elem[i] } [user, grav] end end end end
  9. Thank you very much. Will do.
  10. I want to modify a script that send SMS and I am using a switch statement to send different messages dependent on a condition. The original script works fine but no message is sent with my modified script. I wonder if some part is out of scope? Switch SMS.php
  11. Hi, Thanks for that. I would like to implement the the logic in PHP and I agree that I should try it myself. Thanks
  12. Hi, I am new to JS but OK in PHP. I would like to use JS code similar to this' http://www.geocachingtoolbox.com/index.php?page=dancingMen' a php program. My problem is understanding how this works. I have posted what seem to be the two key functions and my first attempt to simplify things as well as the link the above link in the hope somebody can get my thinking working in the right direction particularly in understanding the two functions. Many thanks for a starter for ten, <script type="text/javascript"> var validChars= new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') var validNums= new Array('0','1','2','3','4','5','6','7','8','9'); function textToIm(){ chars=document.getElementById('dancingMenText').value; splitChars=chars.split(''); newDiv=''; for(i=0; i<splitChars.length; i++){ lowerChar=splitChars[i].toLowerCase(); if (validChars.indexOf(lowerChar)>-1){ if (i+1==splitChars.length || splitChars[i+1]==' ' || splitChars[i+1]=='\n'){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'v.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else{ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; } }else if (validNums.indexOf(lowerChar)>-1){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else if (lowerChar!=' '){ newDiv+=splitChars[i]; } } newDiv = newDiv.replace(/\n\r?/g, '<br>'); if (chars.length==0){ newDiv=''; } document.getElementById('dancingMenDiv').innerHTML=newDiv; } function imToText(char,space){ if (space==1){ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'v.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char+' '; }else{ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char; } } </script> index.php
  13. I am trying to build a simple program to illustrate drawdown in a pension scenario. I have a syntax error that I cant find however. Any help appreciated. <?php if(!$_POST){ ?> <table border=1> <form action="" method="post"> <tr> <td> Initial Capital: <td> <input type="text" name="amount"> <td><br> <td> Growth Rate pa: (in %) <td> <input type="text" name="rate"> <td> Period in Yrs: <td> <input type="text" name="years" maxlength="4"> <td> Yearly Drawdown: <td> <input type="text" name="drawdown" maxlength="5"> <td> <input type="submit"> </form> </table> <?php }else{ if($_POST){ $amount = $_POST['amount']; $rate = $_POST['rate']; $time = $_POST['time']; $number = $_POST['years']; $drawdown = $_POST['drawdown']; $amount2 = (float)$amount; $rate2 = (float)$rate; $drawdown2 =(float)$drawdown; $year = 1 ?> <table border=1> <tr><td> Initial Capital: <?php echo "$start" ?></td> <td>Interest: <?php echo "$rate" ?>%</td> </table> <table border=1> <tr> <th>Years</th> <th>Amount</th> <th>Remaining Capital</th> </tr> <?php while ($year <= $number) { //calculate interest and deduct drawdown $Solve_Interest = ($amount2 * $rate2 * $time) / 100; $Total_Amount = ($amount2 + $Solve_Interest); $Remaining_Capital = ($Total_Amount - $drawdown2); echo "<tr><td>"; echo $year; echo "</td><td>"; echo "<tr><td>"; echo $Solved_Interest; echo "</td><td>"; echo "<tr><td>"; echo $Remaining_Capital; echo "</td><td>"; echo "</tr>"; $year = $year + 1; $amount2 = $Remaining_Capital; } } ?>
  14. change password

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.