Jump to content

flounder

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by flounder

  1. Hi Jacques1, thanks for your help. The strange hex sequences were written to my output file after processing my curl input with simple_html_dom. Replacing $html = new simple_html_dom(); $html->load($result); with $html = new simple_html_dom(); header('Content-Type: text/html; charset=utf-8'); $html->load(utf8_encode($result)); solved my problem. All options now have the right text. Thank you VERY much!
  2. Thanks for your response. The pages I scrape don't have a DTD or a declared character encoding. FireFox displays the pages OK in Quirks mode. My Code Editor identifies the encoding as windows-1252. So I created a page with a few of the problem characters in it: è, ö, ü and ý, saving it in windows-1252 encoding, attached. This works on my terminal: iconv -f WINDOWS-1252 -t UTF-8 input.html outputting è ü ý ö to my screen, but server-side: $file = fopen("input.html","r"); while(! feof($file)) {echo fgets($file);} $file = file('input.html'); foreach ($file as $line_num => $line) {echo $line;} echo file_get_contents('input.html'); All return � � � � As far as I can tell, all PHP file operations retrieve the contents of the file in ASCII, therefore $utf8 = iconv('windows-1252', 'utf-8', $input); fails. I don't think it can be done programatically server-side. Can anyone confirm this? input.html
  3. Hello all, With permission, I scraped a website using curl and simple_html_dom to retrieve 6342 links from 112 pages. While scraping, I converted the links to options for a select element. Most of the options display properly. Here's the problem: there are some ISO 8859-1 hexadecimal encoded characters in the HTML source files, which display as string literals inside options. $input = "<option>Cr\E8me</option>" $input = str_replace("\E8", "è", $input) does not work. How do I turn "<option>Cr\E8me</option>" into "<option>Crème</option>" Any suggestions? TIA.
  4. So it took me a couple of days to figure this out (I'm old and I'm slow). This is what I was looking for: The function function FindNumber($arr, $find) { foreach ($arr as $key => $value) { foreach ($value as $num => $val) { if ($value["num"] == $find) { $result = $value; return $result;}}}} The call passing the parameters: foreach ($lines as $donor => $numbers) { $exploded = explode(",", $numbers); $name = FindNumber($array, $exploded[1]); foreach ($name as $num => $val) { echo $val;}} Works like a charm!
  5. Maybe I'm getting too old for this, I did not receive your response....
  6. xyph, I sent you a PM, it's not showing up in my Sent Items, did you get it?
  7. Yo xyph, thank you very much for taking the time to post what you did. As I stated earlier, I'm quite new to php. However, I've been programming since 1985 starting with a Radio Shack TRS80 with a cassette deck for a storage device. As far as I can tell, my problem currently is the array pointer; I have no idea how to relate your post with my situation, Thanks again, Chris
  8. Thanks xyph, I deleted the redundant $'s from the array_mutisort statement as $membernumber is indeed unique, but again every time the last record is returned, not the one where $exploded[1] = $membernumber[$key].
  9. Hi Nightslyr, that was a helpful hint: I changed my function to: function FindNumber($arr, $find) { foreach ($arr as $key => $row) { if (strncasecmp($find, $membernumber[$key], strlen($find)) == 0) { return ($lastname[$key]}}} The call to the function: foreach ($lines as $donor => $numbers) { $exploded = explode(",", $numbers); FindNumber($array, $exploded[1]); echo $lastname[$key];} Now in each case the very last record gets returned though. I thought the return statement would halt execution of the function and return the current record...
  10. So what am I missing here? I changed the function to: function FindNumber($arr, $find) { foreach ($arr as $key => $row) { if (strncasecmp($find, $membernumber[$key], strlen($find)) == 0) Pass it the arguments: FindNumber($array, $exploded[1]); Stll nothing gets returned....
  11. Hi mikesta707 thanks for the quick response. I'm quite new to php so I'm sorry I have to ask: How do I do that?
  12. Hello all, I have a 14 column csv that I load into an array, retrieving only the required fields, load the array into columns and perform a sort: foreach ($array as $key => $row) { $firstname[$key] = $row["firstn"]; $lastname[$key] = $row["lastn"]; $address1[$key] = $row["addr1"]; $address2[$key] = $row["addr2"]; $address3[$key] = $row["addr3"]; $city[$key] = $row["cit"]; $stateprov[$key] = $row["state"]; $country[$key] = $row["cntry"]; $membernumber[$key] = $row["num"];} array_multisort($membernumber,$lastname,$firstname,$address1,$address2,$address3,$city,$stateprov,$country,$array); When I pass say the first three letters of a last name ($find = "smi"), all records matching the search criteria are returned: foreach ($array as $key => $row) { if (strncasecmp($find, $lastname[$key], strlen($find)) == 0) { echo "<tr><td>" . $firstname[$key] . "</td>"; echo "<td>" . $lastname[$key] . "</td>"; echo "<td>" . $address1[$key] . "</td>"; echo "<td>" . $address2[$key] . "</td>"; echo "<td>" . $address3[$key] . "</td>"; echo "<td>" . $city[$key] . "</td>"; echo "<td>" . $stateprov[$key] . "</td>"; echo "<td>" . $country[$key] . "</td>"; echo "<td>" . $membernumber[$key] . "</td></tr>" . chr(13); }}} So far so good. However, I'd like to put the search part into a function so I can call it a number of times without having to reload the entire csv: function FindMember() { foreach ($array as $key => $row) { if (strncasecmp($find, $membernumber[$key], strlen($find)) == 0) { echo "<tr><td>" . $firstname[$key] . "</td>"; echo "<td>" . $lastname[$key] . "</td>"; echo "<td>" . $address1[$key] . "</td>"; echo "<td>" . $address2[$key] . "</td>"; echo "<td>" . $address3[$key] . "</td>"; echo "<td>" . $city[$key] . "</td>"; echo "<td>" . $stateprov[$key] . "</td>"; echo "<td>" . $country[$key] . "</td>"; echo "<td align='right'>" . $membernumber[$key] . "</td></tr>" . chr(13); }}}} The search criteria would come from a second txt file with every line containing 2 numbers, separated by a comma: foreach ($lines as $member => $numbers) { $exploded = explode(",", $numbers); $find = $exploded[1]; FindMember(); here $exploded[1] corresponds to $membernumber[$key], so this is where I would call the function, but this is where I run into trouble, nothing gets returned. Does this have something to do with the scope of variables inside a user-defined function? I'd appreciate it if someone could point me in the right direction. TIA
  13. Hi Crayon Violet, that's awesome, thank you, thank you, thank you!
  14. Hi Crayon Violet, thanks for the follow up. I already ran into that problem. For example, I tried to retrieve all records matching M*** to Mib*** using array("m","a-i","a-b"); It returned only one record although there were 58 records that should have matched. Scenario 1 is what I'd like it to do....
  15. got it! Again, thanks for all your help.
  16. Hi Crayon Violent, sorry to bother you. I'm trying to return all records in this range: Can**** to Ciz**** This doesn't work $subRanges = "can-ciz"; and neither does this $subRanges = array('c','an-iz'); What's wrong with my logic?
  17. Of course you're absolutely right, my mistake!
  18. Thanks again, Crayon Violet! I didn't know that, thank you. I tried it without {}, the way you suggested in your last post as well as the way I questioned it, all 3 ways work. This is awesome, I can't thank you enough, I'll mark this solved. PS. for anybody following this thread, in the modified function examples $range should read $subRanges
  19. Hi Crayon Violet, I'll try that in a minute, but just looking at the function shouldn't the $subRanges[$k] = (preg_match('~^[a-z]-[a-z]$~i',$v)) ? '['.$v.']' : preg_quote($v); $subRanges = implode('',$subRanges); return preg_match('~^'.$subRanges.'~i',$search); be enclosed in curly brackets?
  20. Hello again, I'm totally new to regular expressions and pattern matching and they are daunting to say the least. The isMatch($base,$range,$search) function provided by Crayon Violet works like a charm for the first two letters. It now appears I need to filter on the first three letters. As far as I can tell, that may be accomplished by inserting {3} somewhere. Is that correct and where do I insert the {3}? !preg_match('~^[a-z]-[a-z]{3}$~i',$range) doesn't work. Thanks again.
  21. Hi Crayon Violent, that's just what I was looking for. Thanks very much!
  22. Hello all, I have this function: strncasecmp($find, $search, strlen($find)) == 0 It returns records from a csv array, $search $find contains the first letter of the last name field, A, B etc. What I would like to do is narrow down the number of records returned to a limited range af letters for example Aa to Ak, Al to Ar etc How would I go about doing this? Thanks in advance.
×
×
  • 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.