Jump to content

doni49

Members
  • Posts

    515
  • Joined

  • Last visited

Everything posted by doni49

  1. I've got something that I think SHOULD work, but it's not. In theory, it should look at every input and allow name & value to be at any position inside the angle brackets. preg_match('/.*<input.+[[value="(.+)"|name="maxpop"]\s+]{1,2}.*>.*/imU',$response,$match); echo "<pre>"; print_r($match); echo "</pre>";
  2. Thanks for the reply. That helped. But it didn't work for all the fields. So I investigated further. I noticed that the fields change the order for value, name and type for example: <input value="value" name="name" type="text"> <input name="name" value="value"type="text"> <input type="text" value="value" name="name"> This sounds like a case for back references. But this is one of the things about regex that I've had the most trouble with.
  3. I'm working on a screen scraping app (to perform tasks on my own WHM panel) and I'm having a bit of difficulty. I need to retrieve the "Value" of ever input put field. Here's a trimmed down copy of what I need to pull the data from. $response = ' <tr><br> <td class="densetbl-key">Max FTP Accounts</td><br> <td class="densetbl-value"><input value="10" type="text" name="maxftp"></input></td><br> </tr><br> <tr><br> <td class="densetbl-key">Max Email Accounts</td><br> <td class="densetbl-value"><input type="text" value="250" name="maxpop"></input></td><br> </tr><br>'; In this example, I need to retrieve 250 from the second input field. Heres what I've tried (and many variations of this) but $match keeps coming back as empty. preg_match('/(\w|\s*)<input value="(\w+)" type="text" name="maxpop">(\w|\s*)/mU',$response,$match); Thanks a bunch!
  4. Well--I just checked CP's file manager. It shows the original as 0kb as well as the copy. Anyone have any ideas why it would tell me it was unable to copy the file when it did? It's also creating an error_log file in the source folder.
  5. I'm on a hosted account w/CPanel access. I've found that after running the script, there is a file in the destination location of the same name as the original file. CP has a 'File Manager'. It tells me the file is 0kb (copy)--I'll have to double check on the size of the original file. When I click on 'Edit File' in the file mgr, it opens the file and the text that was in the original file IS there. So I guess the current Qs are: 1) why is PHP telling me that it couldn't copy is it DID copy? 2) why is CP showing 0kb when the file DOES have text in it? (This last one might be better directed at CPanel).
  6. UPDATE: I've continued to investigate. It SEEMS to be copying the file--but then gives that error message saying that it COULDN'T copy it. The file SAYS 0kb but then has a BUNCH of text in it when I edit the file.
  7. PHP does have read/write permissions to this folder and the files. Another PHP script CREATED most of the files that are in this folder. My head hurts! if (is_dir($dir)) { //get the directory handle if ($dh = opendir($dir)) { //get one filename at a time while (($file = readdir($dh)) !== false) { $files[] = $file; chdir($dir); //make sure $file is not a directory or the error_log file if (!is_dir($file) && !eregi ("^error_log.*$",$file)){ copy($file, $dest . $file); } } } } echo "<br>\nFiles:<pre>"; print_r ($files); echo "</pre>"; The above code outputs the following.
  8. The only problem is that 4.5 to 4.9999999 would round UP. Remember that a number is treated as a string in PHP. Use that to your advantage: $nums = explode(".", $decimal);// <--This will split the decimal number into an array. Element #0 will be the whole number portion and element #1 will be the decimal portion. $wholeNum = $nums[0];
  9. found it there was a typo in the echo statement that's inside of the if statement. Since it wasn't displaying what I expected, I didn't think it was working. Thanks for the assistance!
  10. Interesting theory. But: 1) I thought \n was seen as ONE LINE. A new-line character. 2) the $la array variable was created from this code: $la = explode(" ",$lines[$cnt]); So if anything the newline would be at the end of $la. I was getting ready to post that--but decided to try something first. $l = strlen("\n\nX-Folder:"); // <--returns 11 instead of 9 and changed the if condition to this. if ($la[0] == "\n\nX-Folder:") //<--still doesn't run.
  11. Sure it'll work--if you code it right. Try posting your code. In the meantime, I'll give you an example. $test = 1; while ($test){ echo "Line" . $test . ": "; $c = 1; while($c){ echo $c . "-"; if ($c == 10){ $c = false; echo "<br>"; } } if ($test == 10){$test = 0;} } I haven't tested this to see if there are any typos (hopefully not) but you should be able to get the gist of it. It should output the following:
  12. Get specified characters from a string: http://us2.php.net/manual/en/function.substr.php Get length of string: http://us3.php.net/strlen
  13. P.S. I used strlen on both. strlen($la[0]); // <--returns 13 and strlen("X-Folder:");// <--returns 9
  14. Thanks for the suggestion Andy. You were right. Now I just need to figure out WHY. I (or actually my PHP script) wrote the text file that this is coming from. I'm reading a text file in and trying to pull out the value that follows the colon on the following line. Here's the code that wrote this line to the file. $hdrs[$i-1] = "X-Folder: " . $folder ."\n\n"; $headers = implode("\n", $hdrs); $fname = time(); $filePath = $path . $folders[$folder] . "/"; $filenameTMP = $filePath . "tmp/" . $fname; if (!$handle = fopen($filenameTMP, 'w')) { echo "Cannot open file ($filenameTMP)"; exit; } // Write $somecontent to our opened file. $content = $headers . $message; if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file ($filenameTMP)"; exit; } fclose($handle);
  15. Nope. Just a comment. I put the echo line in there because I wanted to confirm that the $la array had what I thought it did. Here's the more of the code just copy pasted. echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; // echo "Line" . $cnt++ . ": " . $line[$cnt] . "<br>\n"; if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } I put the dashes before and after the variable because I wanted to see if there were any extra characters in there. Thanks guys! That's what the echo line that I have is for. Thanks all for the assistance--this one's been bugging me and I'm sure it's probably a simple typo somewhere. But I've been looking at it for so long, I'm not sure I'll be able to see it myself.
  16. I've been trying to figure this out since last night. PLEASE help me find it. $la[0] contains X-Folder: but the if test seems to think that it doesn't. THis is a code snippet from my code. echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; produces this: But the following if test condition fails: if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; }
  17. Is there a way to have my PHP Script feed a message to SA to be scanned? I can save the message as a text file if that'll help. I'm using a hosted (shared hosting plan) web account with CPanel access. I've noticed that email messages that have been routed through my email forwarders are not being scanned by SA--there is no X-SPAM header. I've asked my host about it and got this reply "It sometimes does not as it is an bug with cpanel". So I'm looking for a way to get the message scanned by SA. And after the message has been scanned, is there someway to let a PHP script know that SA is done with the message? Thanks.
  18. There are two reasons. 1) when I first started learning PHP, I was concerned that by showing exactly what scripting language I was using, I would be making it easier for them to hack my sites. I now have a bunch of HTML files with PHP code in them and would REALLY rather not go through and change them all. 2) From what I've read if the search engines know that a page is scripted, it gives the page a lower rating for the searches (google doesn't like scripted pages). The way that I have my sites set up, there is NO indication that any page is scripted--although with some of them, one would have to be stupid to believe they're not scripted. But it's a now a moot point anyway. I sent my host a support request and he fixed it--I'm still not too sure what went wrong.
  19. I've got a strange issue going on and I don't know what to do about it. I'm using a hosting account (server info is quoted below--copy/pasted from CPanel). I've got my main domain and two add-on domains. I HAD all of them config'd to have all HTML files processed via the PHP engine. Last night, the main domain and one add-on domain stopped processing the PHP code that's in the HTML files but one of the add-on domains is still processing the PHP code. I could have sworn that I used either "Apache Handlers" or "MIME Type" on the CPanel to do this. But I can't get it to work now. When I created a file called phpinfo.php (with one line: <?php phpinfo(); ?>) and loaded it, it DID work. So the PHP engine IS working.
  20. I've been searching for the past 2 hours for this and I can't find it. I'm trying to figure out how to parse email messages in PHP. I'm piping an email address to a PHP script. I've got it so that it recieves the messages in their entirety. But I'm having an impossible time figuring out how to break it down in to the headers, body and attachment(s). Here's a sample of what my script sees when it runs (this is all in one variable). Thanks!
  21. Do you mean see if it's a combination of letters and numbers?  As in validate to see if it' meets your PW and/or username requirements?  If that's what you mean, have a look at www.php.net/ereg and www.php.net/eregi.  Otherwise the is_numeric function to which you were given a link will help.
  22. Not sure if it's the cleanest way, but it should get the job done: [code] <?php function doSort($arr, $key){   $tmp[] = $arr[0];   $arr = array_slice($arr, 1);   foreach ($arr as $a){     $order[] = $a[0];   }   $order = asort($order, TRUE);   foreach($order as $idx =>value){     $tmp[]=$arr[$idx];   }   return $tmp; } $contents = doSort($contents, "index"); ?> [/code]
  23. I haven't tried this myself.  But's in the user submitted notes on www.php.net/array_map. [code] function array_map_recursive($func, $arr) {   $result = array();   do   {       $key = key($arr);       if (is_array(current($arr))) {           $result[$key] = array_map2($func, $arr[$key]);       } else {           $result[$key] = $func(current($arr));       }      } while (next($arr) !== false);   return $result; } [/code]
  24. Personally, I'd prefer the first suggestion myself.  I don't like depending on the user to have javascript enabled--and what about if they're on a device that doesn't even have javascript?
  25. [code] <?php $test = "my dog"; $test2 = strtoupper(substr($test, 0, 1)) . substr($test,1); ?> [/code]
×
×
  • 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.