Jump to content

loco41211

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Everything posted by loco41211

  1. I can't work out how to use is_readable with an array of directories. Could anyone explain for me place how I could make this work? foreach ($users as $user) { $usernames[] = $user['username']; $homedirs[] = $user['home_dir']; } if (($usernames!="")) { if (is_readable($homedirs)) { array_push($path_to_public,$homedirs); } } I get the error: Appreciate any help thank you in advace.
  2. Your 'hybrid' of both matches didn't match the inbetween apostrophes for some reason. I have come up with this, and it seems to work: preg_match_all("/\"([^\"]+)\"/", $line, $matches); else preg_match_all('/\'([^\"]+)\'/', $line, $matches); $pass = $matches[1][0]; return $pass; Thank you for the help, it's much appreciated!
  3. It worked! I used this preg_match_all("/\"([^\"]+)\"/", $line, $matches); $pass = $matches[1][0]; return $pass; One last question, what would the regex be to preg_match the value between apostrophe marks? for example $variable = 'hello';
  4. Changing the bits to if (strrpos($line,'"')) $getuser=substr($line,(strpos($line,'"')+1),(strrpos($line,'"')-(strpos($line,'"')+1))); else $getuser=substr($line,(strpos($line,"'")+1),(strrpos($line,"'")-(strpos($line,"'")+1))); return $getuser; Seemed to do the trick! But it looks messy, and I don't know if it will always work as needed so I'm going to try and implement your idea. Thank you, I'll post an update in a bit once I figure out how to implement what you gave me.
  5. Here is the full bit for that section: function get_user($link) { $config=fopen($link,'r'); while(!feof($config)) { $line=fgets($config); if (strstr($line,'user') or strstr($line,'username') { if (strrpos($line,'"')) $getuser=substr($line,(strpos($line,'=')+3),(strrpos($line,'"')-(strpos($line,'=')+3))); else $getuser =substr($line,(strpos($line,'=')+3),(strrpos($line,"'")-(strpos($line,'=')+3))); return $getuser; I had a thought, the script thinks the username stops where the quotation mark is. Would there be a way of getting it to check " to " ? In other words, what's in the quotation marks after the variable name is found?
  6. It sadly isn't an option. Yes I though preg_match could do this, but I have no idea on how to formulate it... Hang on and I'll note out what the input and output for that section of the script is, and what the full section is. Just to clear it up. I'll post it all here in roughly 10 or so minutes.
  7. To simplify the scenario: I have a php script that opens given files and checks the value of a set of matching variables in that file. The line of code that extracts the variable is: $extr=substr($line,(strpos($line,'=')+3),(strrpos($line,'"')-(strpos($line,'=')+3))); The problem with this code is that it only works with code like this: $variable = "hello"; If there are more or less than 3 strpos, or whatever you want to call it, for example: $variable="hello"; or $variable = "hello"; then the script is useless and can't finish the job its meant to do. Could anybody suggest an improvement? or a way around this? ANY suggestions or ideas are welcome, post away! Addition: Someone else said would anybody here know what to make of this? I'm not good at all with regex...
  8. Thank you for the help everybody. I am happy to say that the problem has been fixed. It wasn't todo with the fopen function, I made a stupid mistake at a later section which is why it wouldn't work properly on my test server.
  9. Hello, I am trying to make a php script to fetch the simple cumulative-stats uploadedBytes and downloadedBytes and to add them together. The fetch is done via rpc on transmission (a torrent client). At the current step I have come across a 409 error. When trying it in command line on the server using ssh I get the following output: http://locotest2.co.cc/a.html I asked on irc but nobody seems to be in the mood to help with this. The rpc specs I was given to use with my script are at 4.2 here: http://trac.transmissionbt.com/browser/trunk/doc/rpc-spec.txt A guy gave me this pastie on the transmission channel to edit for my own needs: http://pastie.org/338555 I have made a few changes but I need to add a header as per the response I get from curl (see the a.html link above). Here is my current script: <? function do_post_request($url, $data) { $params = array( "http" => array( "method" => "POST", "content" => $data ) ); print_r($params);die; $ctx = stream_context_create($params); file_get_contents($url); die ($fp); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } /* Construct the request array */ $request = array( "method" => "session-stats", "X-Transmission-Session-Id" => "6YNbfQSfeewqGnoXwNSlDQVcosRS5ooRgq6yAIwc6C9CFlMF", "arguments" => array( ) ); /* Do the actual request, decode the reply JSON string into a PHP object */ try { $reply = die(do_post_request("http://localhost:9091/transmission/rpc", json_encode($request))); } catch (Exception $e) { exit(); } /* The reply contains a list 'torrents' of objects with our requested fields */ if ($reply->arguments["cumulative-stats"]->uploadedBytes + $reply->arguments["cumulative-stats"]->downloadedBytes > 6*1024*1024*1024) { /* response triggered command here */ } ?> Can someone help me get this working? I'm logged on irc.freenode.net with the username loco if its easier to go through it there. I am extremely grateful for any help on this. Especially if someone can rewrite this for me! Awaiting your answers, loco
×
×
  • 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.