Jump to content

mrphobos

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mrphobos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Upon further reading, is using PCRE conditions really the easiest way to do this. It would appear I'll have to spend days learning the PCRE system. Can any one confirm the cpu work load is whats causing the scrypt to stop? In which case, wouldn't it be easier to do this part in python?
  2. 1) Are there always 4 fields (i.e. 403089 RESIDENTIAL Residential 385000) before the start of the address? No, some lines have more than one word for the second and third field.. 2) Is the 'S x y z' pattern at the end of the address always an S followed by 3 numbers? No, it's always followed by numbers but some times the S a R or some thing else 3) How about addresses that contain an 'S' for South (i.e. 7610 S Lakeshore Dr. Harbor Springs)? Yes, I've run in to this problem. That's what the other if then statements are for. The value after the 'S' are always numeric and the value before is never numeric. I'm unfamilier with the code you've posted. $pattern = "/\d+\s+\w+\s+\w+\s+\d+\s+(.*?)\s+S\s+\d{1}\s+\d{1}\s+\d{1}"; is this line finding all the 's''es?
  3. I'm attempting to praise(if that's how you say it) txt data into xml with php and have come across a problem I've been unable to solve over the past two days so I'm coming here to ask the php gods for their assistance. The file I'm prasing contains line after line of real estate data. I understand what I'm doing I think. I've gotten the data in a format that is more usable, taking out the tabs and replacing them with spaces and such. I am creating a series of if than statements which will select the address out of each line even though each line can be different. At the end of the address on each line there is a "S" character which stands for some property I'm not concerned with. I'm simply using the single 'S' to find the end of the address. The lines look like so: \/ 403089 RESIDENTIAL Residential 385000 7610 N Lakeshore Dr. Harbor Springs S 3 2 0 None 3 Litzenburger, Boo Schaffer Real Estate 399562 RESIDENTIAL Condominium 155000 4749 Pleasantview Road Harbor Springs S 2 2 0 One Hartwick, Bob Coldwell Banker Schmidt With a bunch of extra text following that I've trimmed off for our purposes here. See the 'S' after the town? I've created the following code to look for the 's' in relation to the word order. <?php // Listings file $listings= file('listingsTest.txt'); $i = 0; $j = 0; $_ENV['a'] = 0; foreach($listings as $value) { //Replace all spaces of every kinds with single spaces $listings[$i] = preg_replace("'\s+'", ' ', $listings[$i]); //Put all characters into an array corisopndings to each line in $listings $_ENV['chars'.$i] = preg_split('//', $listings[$i]); //Place all words and uninterupted numbers and place in array $words $_ENV['words'.$i] = preg_split('/ /', $listings[$i]); $i++; } //echo $_ENV['chars'.'1']['1']; foreach($_ENV['words'.$_ENV['a']] as $char){ $countedf = preg_split('//', $_ENV['words'.$_ENV['a']][$j]); $counted = count($countedf) - 2; $wordBeforef = preg_split('//', $_ENV['words'.$_ENV['a']][$j-1]); $wordBefore = count($wordBeforef) - 2; $wordAfterf = preg_split('//', $_ENV['words'.$_ENV['a']][$j+1]); $wordAfter = count($wordAfterf) - 2; if( ($counted == 1) && ($wordAfter == 1) && (is_numeric($_ENV['words'.$_ENV['a']][$j+1])) //&& ($wordBefore == 1) //&& (!is_numeric($_ENV['words'.$_ENV['a']][$j])) //&& (is_numeric($_ENV['words'.$_ENV['a']][$j+2])) //&& ($_ENV['words'.$_ENV['a']][$j+3] == ' ' ) ){ echo '*'; echo $_ENV['words'.$_ENV['a']][$j]; echo '*'; $_ENV['a']++; $j =0; //$j=1 } //echo $_ENV['chars'.$_ENV['a']][$j]; $j++; } ?> As you can see from the if then statements, I've gotten to the point where It's replying to the 'S' at the end of the address thus telling me where the address ends. I am however having a problem I believe is a server issue. The code works fine when applied to 12 lines like the ones above, when I apply it to more of those lines it does not return the 'S' for them even if I used the exact same line more than 12 times. The main file which I'd like to automate the parsing of has thousands of these such lines in it. If I try to apply this code to the file with these thousands of lines, the browser returns a "The website encountered an error while retrieving http://localhost. It may be down for maintenance or configured incorrectly". I take this to mean the server is doing too much work for it to be completed. I think when it reaches it's twelfth, the temporary memory of my program/server or some thing else, is exhausted. I'm applying these if then statements to every single word in the file. Is this a processing issue on the server? I was applying this code to every character in the file and thought I could fix the problem by applying instead to every word given there are less words than characters. I have the processing time on the server set to 10000 and it's not taking along time to return the error message. I would be very grateful to any help any of you could provide. Thank you for your time.
  4. I'm attempting to use php to automate the process of unzipping the contents of a number of .gz and .tar files I have into a folder. I've spend several hours weighing my options and at this simple noob planing stage I'd just like to know what my options are. The only commands that are built into php that appear to be useful in this effort are the zlib library. I've found zlib.output_compression on my server and enabled it so am I correct in assuming I can use these functions now? Zlib Functions gzclose — Close an open gz-file pointer gzcompress — Compress a string gzdecode — Decodes a gzip compressed string gzdeflate — Deflate a string gzencode — Create a gzip compressed string gzeof — Test for EOF on a gz-file pointer gzfile — Read entire gz-file into an array gzgetc — Get character from gz-file pointer gzgets — Get line from file pointer gzgetss — Get line from gz-file pointer and strip HTML tags gzinflate — Inflate a deflated string gzopen — Open gz-file gzpassthru — Output all remaining data on a gz-file pointer gzputs — Alias of gzwrite gzread — Binary-safe gz-file read gzrewind — Rewind the position of a gz-file pointer gzseek — Seek on a gz-file pointer gztell — Tell gz-file pointer read/write position gzuncompress — Uncompress a compressed string gzwrite — Binary-safe gz-file write readgzfile — Output a gz-file zlib_get_coding_type — Returns the coding type used for output compression Secondly, I don't understand which function I need to use for this. I just want to take the contents of a .gz or .tar folder and place them in another. I don't think I'm grasping the language of the php documentation. Take for instance "readgzfile"s description, "Reads a file, decompresses it and writes it to standard output." Does that mean it decompresses the file and takes it's content and outputs them? It doesn't appear to based on it's properties. Any help any of you could give me would be greatly appreciated. I'm not looking for a hand out, I'm just looking for which path to take. Thanks.
  5. Hey thanks for your reply. I knew there was some thing vital I was missing. The following is the exact line I'm using if (ftp_get($resource, '/var/www/downloads/'.$files[$i], $files[$i], FTP_BINARY)){ Every thing else is the same. When run, the script returns the same error for every file it tries to download. Theres about 30 of them so I won't copy past the whole thing but here's the first one. Warning: ftp_get(/var/www/downloads/fileIDX/pics-multi family-20100216.tar) [function.ftp-get]: failed to open stream: No such file or directory in /var/www/gwr/connect.php on line 30 It's almost as if it needs the file to already be there before it can replace it. I don't understand what's going on here. Does any one have any suggestions. Thank you for your time.
  6. Greetings all! ;)I'm writing a php script that will connect to a ftp server and download all the files in the main array. I've got the connection part down. I know how to download specific files and I'm attempting to download ALL the files by listing them in a array and then using a FOR incremental loop to go through one by one and use FTP_get to download each one. I think I'm ALMOST there with this code. It isn't giving me any errors, <?php $countfiles = 0; //Connnect to FTP server $resource = ftp_connect('idx.fnismls.com'); $login = ftp_login($resource, '*********************', '************'); if($login){ printf("****We are now connected****"); printf("<br>"); }else{ printf("****Connection faild****"); printf("<br>"); } //Puts file names into an array. $files = ftp_nlist($resource,"IDX"); //Counts and Gets each file with $files[$i] variable. for($i = 0; $i < count($files); $i++) { echo $files[$i]; printf("<br>"); $countfiles++; echo "$countfiles ..."; //Download section if (ftp_get($resource, '/var/www/downloads', $files[$i], FTP_BINARY)){ printf("...File downloaded correctly"); printf("<br>"); }else{ printf("...File not downloaded correctly"); printf("<br>"); } } ?> When I take out the download section, the out put will list all the files one by one. If I let it run as is, it will run and run never ending which means the for loop condition of $I <count($files); isn't being met. I simply don't understand why. Any help would be greatly appreciated. I think I'm ALMOST there.
  7. Thank you for your reply. That apparently was the problem because it works now. I can download files one by one. The only issue that I can't seem to find solutions for by googleing it is how to select and download all the files in the folder without typing them each in. Thank you for your help.
  8. Hello wise and merciful PHP elders. I'm attempting to setup/learn how to use FTP with php. I've written the following script. PHP Code: <?php $resource = ftp_connect('hidden'); $login = ftp_login($resource, 'hidden', 'hidden'); if($login){ printf("We are now connected"); }else{ printf("Connection faild"); } $list = ftp_rawlist($resource, '/idx', true); if (ftp_get($resource, '/var/www/downloads', '/IDX/features.txt.gz', FTP_BINARY)){ printf("...Files downloaded correctly"); }else{ printf("...Files not downloaded correctly"); } ?> In this script I'm attempting to download a file from the directory I know exists. The script logs in successfully and tells me "We are now connected...Files downloaded correctly", But there's no files in the directory and none appear to be downloaded. I told it to download a specific file that I know is inside there because I didn't know how to tell it to download all the files. When I change the downloads folder to a text file called download.txt the result is the same. My best guess is it has some thing to do with the files being .text.gz or perhaps it's some thing to do with the localhost downloads directory. I'm still looking into the problem but am not getting any where. I'm stuck and my wheels are spinning. Any help any of you could provide would be greatly appreciated. Thank you for your time.
  9. Your right, it works now. I can't believe I over looked that. Thank you both for your help. I currently have a admin page that can update a few tables in a database, however, one of the inputs to update the database is a html textarea. When I update the tables without entering information into the textarea it erases the data already in the database feild for that textarea but when I do the same for a input textfeild it doesn't. It's also doing this for the drop down. Just not the textfeilds. The if statements I've written to take care of this issue don't seem to be working. Does any know if text area's aren't supported by php? Here's the code, Any additional help you guys can provide would be greatly appreciated. <html> <head> <title></title> <link rel="stylesheet" type="text/css" href=""/> </head> <body> <form action="admin.php" method="post"> <table border="1"> <tr> <th>Header:</th> <td> <input type="textfeild" name="header" /><br/></td> </tr> <tr> <th>Header Font</th> <td> <?php //Header font drop down include "connect.php"; $query="SELECT font FROM headerfont"; $result=mysql_query($query); echo "<select name=\"font\">"; echo "<option value=\"None chosen\">Choose header font:</option>\n"; while($row = mysql_fetch_assoc($result)){ $font = trim($row["font"]); echo "<option value=\"". $font ."\">" . $font . "</option>\n"; } echo "</select>"; $updatefont ="$_POST[font]"; echo $updatefont; if($updatefont == ""){ echo "Header font not updated"; }else{ $query="UPDATE currentfont set headerfont = '$updatefont'"; mysql_query($query); } ?> </td> </tr> <tr> <th>Content:</th> <td> <textarea rows="10" cols="40" name="content"> </textarea><br/></td> </tr> <tr> <th>Footer:</th> <td> <input type="textfeild" name="footer" /><br/></td> </tr> <tr> <td><input type="submit" value="update the site"/></td> </tr> </table> </form> <br/> <?php include "connect.php"; $updateheader = "$_POST[header]"; $updatecontent = "$_POST[content]"; $updatefooter = "$_POST[footer]"; //Update header if ($updateheader == "") { echo 'Header feild empty'; } else { $query = "UPDATE feilds SET header = '$updateheader'"; mysql_query($query); } ?> <br/> <? //Update content if ($updatecontent == "") { echo "Content feild empty"; } else { $query= "UPDATE feilds SET content ='$updatecontent'"; mysql_query($query); } ?> <br/> <? //Update footer if ($updatefooter == "") { echo "Footer feild empty"; } else { $query= "UPDATE feilds SET footer ='$updatefooter'"; mysql_query($query); } mysql_close($con); ?> View the site by clicking<a href="index.php"><u> here.</u></a> </body> </html>
  10. I'm trying to create a database driven drop down menu. I feel I'm on to the right path but my code doesn't seem to work. I've looked around and haven't seen where I'm making the mistake. Any one care to take a look? //Header font drop down include "connect.php"; $query="SELECT font FROM headerfont"; $result=mysql_query($query); $num = mysql_numrows($result); $row=mysql_fetch_array($result); echo "<select name=\"font\">"; echo "<option value=\"None shosen\">Choose:</option>\n"; for($i=0; $i<$num;$i++){ echo "<option value=\"".trim($row[$i])."</option>\n"; } echo "</select>"; As you can see I'm trying to get this loop to cycle through all the items in table and print out the different fonts the user can pick from. Right now the drop down menu displays blank spaces instead of the names in the table. I'd like to be able to take the font the user picks and put it into a variable to be stored on the database. Is this a workable method? I'm really shooting at he dark on this one. Any help would be greatly appreciated.
×
×
  • 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.