Jump to content

gamefreak13

Members
  • Posts

    96
  • Joined

  • Last visited

Everything posted by gamefreak13

  1. I've done that. I get several errors. Below is the code with the [3]'s changed to [4]'s. Note the last line of the output is "6 --- / --- 1 --- c, R, C, <br>". I can't make heads or tails of the output other than that it looks like the first 3 parts are from the 6/10/2013 date. <?php require 'simple_html_dom.php'; $sHtml = file_get_contents("http://axpxpxsx.sxaxnxdxixexgxox.gxoxvx/sxdxfxixrxexdxixsxpxaxtxcxhx/"); $oHTML = str_get_html($sHtml); $oTRs = $oHTML->find('table tr'); foreach($oTRs as $oTR) { $fdarray = array(); $oTDs = $oTR->find('td'); foreach($oTDs as $oTD) { $fdarray[] = trim($oTD->plaintext); } } print_r($fdarray); echo "\n\n\n\n\n<hr>\n\n\n\n\n\n"; $new = array(); foreach ($fdarray as $arr) { $key = join('|', array_slice($arr,0,3)); if (isset($new[$key])) { $new[$key][4][] = $arr[4]; } else { $new[$key] = array ($arr[0], $arr[1], $arr[2], array($arr[4])); } } foreach ($new as $arr) { echo "\n\n\n\n\n\n\n<hr>\n\n"; echo $arr[0]." --- ".$arr[1]." --- ".$arr[2]." --- ".join(', ', $arr[4])."<br>\n"; } ?> And the output is.. Array ( [0] => 6/10/2013 9:44:50 PM [1] => Medical [2] => DANDRIDGE LN [3] => FAIRCROSS PL/Dead End [4] => M12 ) <hr> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/test.php</b> on line <b>26</b><br /> <hr> 6 --- / --- 1 --- c, R, C, <br>
  2. I double-posted because my other thread is far too in depth and confusing, so most members probably just skipped right over it. The suggestions are not working (probably because I changed the data structure to try to simplify things, but really it just made it impossible for me to use the suggestions). So I thought I'd simplify things by starting a new thread.
  3. I tried this and it seems to work fine, thank you. Need I worry about varying lengths breaking this? If I'm understanding your code correctly, it searches for forward slashes and semi-colons to seperate the year, month, day, etc. I'll do some testing (like throwing 06/08/2013 at it instead of 6/8/2013), but thought I'd ask too.
  4. This is the output of my array (yes it outputs an empty array too): Array ( ) Array ( [0] => 6/9/2013 10:36:54 PM [1] => Medical [2] => BROADWAY AVE [3] => FAKE RD/BOGUS LN [4] => E42 ) Array ( [0] => 6/9/2013 10:36:54 PM [1] => Medical [2] => BROADWAY AVE [3] => FAKE RD/BOGUS LN [4] => MR40 ) Array ( [0] => 6/9/2013 10:29:01 PM [1] => Vehicle Rescue [2] => I-15 NB [3] => [4] => E37 ) Array ( [0] => 6/9/2013 10:29:01 PM [1] => Vehicle Rescue [2] => I-15 NB [3] => [4] => M37 ) Array ( [0] => 6/9/2013 10:29:01 PM [1] => Vehicle Rescue [2] => I-15 NB [3] => [4] => MR38 ) Array ( [0] => 6/9/2013 10:28:21 PM [1] => Medical [2] => MAIN ST [3] => SOME ST/NOWHERE DR [4] => E33 ) Array ( [0] => 6/9/2013 10:28:21 PM [1] => Medical [2] => MAIN ST [3] => SOME ST/NOWHERE DR [4] => MR33 ) I need to combine [4] together (seperated by commas) if [0] through [3] are the same. The naming is as follows: 0 = time 1 = type 2 = address 3 = cross streets 4 = units/apparatus Desired output of the above array: Array ( [0] => 6/9/2013 10:36:54 PM [1] => Medical [2] => BROADWAY AVE [3] => FAKE RD/BOGUS LN [4] => E42, MR40 ) Array ( [0] => 6/9/2013 10:29:01 PM [1] => Vehicle Rescue [2] => I-15 NB [3] => [4] => E37, M37, MR38 ) Array ( [0] => 6/9/2013 10:28:21 PM [1] => Medical [2] => MAIN ST [3] => SOME ST/NOWHERE DR [4] => E33, MR33 )
  5. Thank you VERY much! It's that xpath part that I couldn't figure out. I've managed to get past that major hurdle thanks to you and am now flying by at light speed with my project, thank you!
  6. SimpleXML should have no problem with it. There are 5900 lines (but it can fluctuate by a few thousand) of XML. I think SimpleXML is how I'll need to go, but my problem is the structure of the data, I don't know how to specify the path/locations of the data I want to get. It should be noted that this PHP script will be ran about every 30-60 seconds for the rest of forever to fetch the XML file. This script will (as I build upon it) retrieve the small portion of the XML I need, and insert it to a MySQL database. I know how to do the rest, I just don't know how to get the data I need from the XML.
  7. I need to parse a very large XML file. About 80% of the XML file is irrelivant, and I only need data inside a certain route. Below is a short example. I need data within State>Center (where ID="INHB")>Dispatch (where ID="BCCC")>. <State> <Center ID="SAHB">...</Center> <Center ID="GGHB">...</Center> <Center ID="LAHB">...</Center> <Center ID="INHB"> <Dispatch ID="INCC">...</Dispatch> <Dispatch ID="OCCC">...</Dispatch> <Dispatch ID="BSCC">...</Dispatch> <Dispatch ID="ICCC">...</Dispatch> <Dispatch ID="BCCC"> <Log ID="130608BC00896"> <LogTime>"Jun 8 2013 4:06PM"</LogTime> <LogType>"Log Type Here"</LogType> <Location>"Location Here"</Location> <LocationDesc>"A Description Of The Location Here"</LocationDesc> <Area>"City Here"</Area> <ThomasBrothers>""</ThomasBrothers> <LATLON>"33434943:117141729"</LATLON> <LogDetails> <details> <DetailTime>"Jun 8 2013 4:06PM"</DetailTime> <IncidentDetail>"line 1"</IncidentDetail> <IncidentDetail>"line 2"</IncidentDetail> <IncidentDetail>"line 3"</IncidentDetail> </details> </LogDetails> </Log> <Log ID="130608BC00879"> etc etc etc </Log> </Dispatch> <Dispatch ID="BICC">...</Dispatch> <Dispatch ID="ECCC">...</Dispatch> <Dispatch ID="CTCC">...</Dispatch> </Center> </State> What I would really love to end up with is a variable for every portion of information. For example: $LogID $LogTime $LogType $Location $LocationDesc $Area $ThomasBrothers $LATLON $DetailTime $IncidentDetail[] (PHP array for each line) All of which are in a foreach loop for each $LogID. My problem is traversing the structure. Can anyone help me get started with some basic code to build upon (specifically in relation to the structure I've presented)?
  8. Is there a way to do this prior to PHP 5.3? I have PHP 5.2.9 and DateTime is not available. Fatal error: Call to undefined method DateTime::createfromformat()
  9. Thank you both for your replies. In my effort to simplify/remove things for this thread, it seems I've made things more difficult. Below Barand's code intermingled with my code that returns the array of data. I've done something horribly wrong, and can't get it to work. Below is the entire PHP code (note the require_once of simple_html_dom.php though) and the raw HTML output when the PHP code is ran. If you need the common simple_html_dom.php file, it can be downloaded at http://sourceforge.net/projects/simplehtmldom/files/ Please replace all X's in the following URL for the actual source data (and therefore PHP array). PLEASE, do not post the actual link. I don't need search engines picking it up, and this forum doesn't allow editing of posts. And yes Barand, I intend to insert the list of units (e.g. "E21, M31, MR44") together as a text string in MySQL. <?php require 'simple_html_dom.php'; $sHtml = file_get_contents("http://axpxpxsx.sxaxnxdxixexgxox.gxoxvx/sxdxfxixrxexdxixsxpxaxtxcxhx/"); $oHTML = str_get_html($sHtml); $oTRs = $oHTML->find('table tr'); foreach($oTRs as $oTR) { $fdarray = array(); $oTDs = $oTR->find('td'); foreach($oTDs as $oTD) { $fdarray[] = trim($oTD->plaintext); } } print_r($fdarray); echo "\n\n\n\n\n<hr>\n\n\n\n\n\n"; $new = array(); foreach ($fdarray as $arr) { $key = join('|', array_slice($arr,0,3)); if (isset($new[$key])) { $new[$key][3][] = $arr[3]; } else { $new[$key] = array ($arr[0], $arr[1], $arr[2], array($arr[3])); } } foreach ($new as $arr) { echo "\n\n\n\n\n\n\n<hr>\n\n"; echo $arr[0]." --- ".$arr[1]." --- ".$arr[2]." --- ".join(', ', $arr[3])."<br>\n"; } ?> Array ( [0] => 6/8/2013 2:00:17 PM [1] => Medical [2] => TRIANA ST [3] => [4] => M36 ) (note the [3] really was empty and is normal, that table column was empty for that specific row) <hr> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: array_slice() expects parameter 1 to be array, string given in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <br /> <b>Warning</b>: join() [<a href='function.join'>function.join</a>]: Invalid arguments passed in <b>/home/mysite/public_html/firedept/testing.php</b> on line <b>26</b><br /> <hr> 6 --- / --- 8 --- /, i, A, , <br>
  10. I know I can use strtotime(), but I would feel safer specifying the format. How do I convert "6/8/2013 1:01:27 AM" into a unix time stamp while specifying "M/D/Y H:M:S (am/pm)" format? $date = strtotime('6/8/2013 1:01:27 AM'); echo $date;
  11. In an effort to make this easier for those helping, this may just be a simple matter of working with PHP Arrays. Based on the above code, I removed all the ECHO's and changed it to print_r($aRow); and got this array. Now if only I knew how to work with arrays. Array ( ) Array ( [0] => 1:01:27 AM [1] => MEDICAL [2] => MAIN ST [3] => E3 ) Array ( [0] => 1:01:27 AM [1] => MEDICAL [2] => MAIN ST [3] => M36 ) Array ( [0] => 12:35:51 AM [1] => RESCUE [2] => BROADWAY AVE [3] => E20 ) Array ( [0] => 12:35:51 AM [1] => RESCUE [2] => BROADWAY AVE [3] => M31 ) Array ( [0] => 12:35:51 AM [1] => RESCUE [2] => BROADWAY AVE [3] => M20 ) Array ( [0] => 12:16:45 AM [1] => MEDICAL [2] => 2ND ST [3] => E17 ) Array ( [0] => 12:16:45 AM [1] => MEDICAL [2] => 2ND ST [3] => M62 )
  12. I can't edit the title of the thread, but this does not involve any MySQL whatsoever at this point. I will eventually be inserting the data into a MySQL database, but that has nothing to do with my question, so please disregard the MySQL title.
  13. I am fetching an HTML table using the Simple HTML DOM Parser. I get $col[0], $col[1], $col[3] and $col[4] for each row in the HTML table, these are columns. This is ran through a foreach to loop through every row. For testing purposes, I output the following: $col[0] --- $col[1] --- $col[2] --- $col[3] 11:23:26 PM ---- MEDICAL ---- 41ST ST ---- E19 11:23:26 PM ---- MEDICAL ---- 41ST ST ---- M12 10:45:26 PM ---- MEDICAL ---- MAIN ST ---- E20 10:45:26 PM ---- MEDICAL ---- MAIN ST ---- M62 10:45:26 PM ---- MEDICAL ---- MAIN ST ---- T20 09:49:19 PM ---- RESCUE ---- BROADWAY AVE ---- E27 The first three colums are always identical for the grouping. The third column is what is different. I want to combine the data like so: 11:23:26 PM ---- MEDICAL ---- 41ST ST ---- E19, M12 10:45:26 PM ---- MEDICAL ---- MAIN ST ---- E20, M62, T20 09:49:19 PM ---- RESCUE ---- BROADWAY AVE ---- E27 How would I detect that "if columns 1, 2 and 3 are the same, then take the data from column 4 for each row"? Note that the number of rows could fluctuate between 1 to around 10-15 on average. Each row specifies a different apparatus/unit (this is a fire department listing of incidents), but this wastes a lot of vertical space and is overly redundant. My specific code is below: <?php require 'simple_html_dom.php'; $url = "http://www.website.com/html_table.html"; $sHtml = file_get_contents($url); $oHTML = str_get_html($sHtml); $oTRs = $oHTML->find('table tr'); $aData = array(); foreach($oTRs as $oTR) { $aRow = array(); $oTDs = $oTR->find('td'); foreach($oTDs as $oTD) { $aRow[] = trim($oTD->plaintext); } echo $aRow[0]; echo " ---- "; echo $aRow[1]; echo " ---- "; echo $aRow[2]; echo " ---- "; echo $aRow[3]; echo "<br>\n"; $aData[] = $aRow; } ?>
  14. This doesn't work perfectly. Granted, the usernames should only contain letters and numbers and underscores and hypens, but something like myspace.com/contactus (example) would return contactus when thats not a myspace profile. Maybe I could do a list of banned results? <?php $sometext = "myspace.com/bluemonkey00&var=something&test=ok"; $sometext= pathinfo($sometext); print_r($sometext['filename']); ?> Outputs bluemonkey00&var=something&test=ok
  15. Thanks.. I tried adding just the sort part and it worked but I didn't realize it because it outputted a bunch of empty lines so the page appeared to be blank to me. I tried it again after reading your post and noticed the scrollbar. Doh! Thanks!
  16. Can you be a little more specific? I added this under $output = explode... and I get "Warning: Invalid argument supplied for foreach() in readtxt.php on line 17". sort($output); foreach($output as $key => $val) { $output = "output[" . $key . "] = " . $val . "\n"; }
  17. I have hundreds of sentences (one per line) and need to sort them all alphabetically and numerically. And not just for the first letter.. I want it to sort it as far as possible. Example input: What was the last drink you had? What was the last movie you watched? What was the last 11.. just inserting a number here as an example? What was the last book you read? Example output: What was the last 11.. just inserting a number here as an example? What was the last book you read? What was the last drink you had? What was the last movie you watched? This is my code I am using right now to read my text file and output it on my page (which is formatted as a MySQL INSERT query). <?php $file = "sentences.txt"; $fp = fopen($file, "r"); $data = fread($fp, filesize($file)); fclose($fp); $output = explode("\n", $data); foreach($output as $var) { if($var == "") { echo "<br>"; } else { echo "INSERT INTO survey SET question='$var';<br>"; } } echo "Done!"; ?>
  18. I don't really understand the problem? Can you re-explain it? And without knowing how the functions are setup, it's pretty hard to understand it. Also, you can simplify the following code alot. <?php include("includes/Connect.php"); include("includes/functions.php"); mysql_select_db("divnxn5_web"); $user = $_POST['username']; $pass = md5($_POST['password']); //MYSQL Injection $user = stripslashes($user); $pass = stripslashes($pass); $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); Put mysql_select_db("divnxn5_web"); in includes/Connect.php under mysql_connect. Make sure to remove it from any files that include the Connect.php file, because otherwise it will select it twice. <?php include("includes/Connect.php"); include("includes/functions.php"); $user = mysql_real_escape_string(stripslashes($_POST['username'])); $pass = md5(mysql_real_escape_string(stripslashes($_POST['password'])));
  19. Also.. I assume that code is it's own page like logout.php. Otherwise, do something like index.php?do=logout. The log out page should not contain anything else except the code I quoted. Your members do not see the page as it happens in a split second, so there is no need to do a layout or anything since you're redirecting them to your homepage again anyway. So if your on index.php, click index.php?do=logout, it will execute the code and then instantaneously redirect you to index.php. This would work in index.php : if($_GET['do'] == "logout") { $user = $_COOKIE['user']; $id = $_COOKIE['rank']; session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); setcookie("rank", $id, time()-(60*60*24*365)); header("location: index.php"); exit(); }
  20. According to your code I do not see any other headers being sent or any data before it. Headers must be sent before ANY content is shown, but after everything thats needs to be run is done. This would work : <?php $user = $_COOKIE['user']; $id = $_COOKIE['rank']; session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); setcookie("rank", $id, time()-(60*60*24*365)); header("location: index.php"); ?> But these examples below would not.. <?php $user = $_COOKIE['user']; $id = $_COOKIE['rank']; session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); setcookie("rank", $id, time()-(60*60*24*365)); echo "Hello world"; header("location: index.php"); ?> <?php include("header.php"); $user = $_COOKIE['user']; $id = $_COOKIE['rank']; session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); setcookie("rank", $id, time()-(60*60*24*365)); header("location: index.php"); ?> <html> <body> <?php $user = $_COOKIE['user']; $id = $_COOKIE['rank']; session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); setcookie("rank", $id, time()-(60*60*24*365)); header("location: index.php"); ?> </body> </html>
  21. Not trying to be rude, but this is what Google is for. Honestly, if I were to want to find such a script I would Google "php newsletter script" or "php search engine script". The newsletter script would be incredibly easy to make. Subscribe.php enters an email to the database, unsubscribe.php removes it from the database, and newsletter.php (for admin) would use send the emails out using the php mail() function. I could write one for you right now, but I know there are plenty already out there.. and probably have more features too.
  22. Also.. remove the javascript and add this above the closing bracket. If your visitor has javascript disabled they will just see a blank page.. plus that is invalid HTML because the html, head, and body tags are missing. header("location: index.php");
  23. It works!! Awesome! Many thanks! I do wonder though.. do I have to use mysql_num_rows or can I do something like .. if($result > 0) { ? The reason I ask is because I'm running some insane queries on the page already. Does that count for two queries or just one? Like.. does $result run ONCE, and then whatever the value is.. it gets questioned by mysql_num_rows and by $line['name'] ? Oh.. and by "blank" I meant just where my PHP code was. The entire page wasn't blank white. I have E_ALL set at the top of my script already, so whatever was wrong with my code must have been considered "normal"?
×
×
  • 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.