Jump to content

schapel

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by schapel

  1. Just in case anyone runs into this, I found a solution myself. I'm not sure if it's the most efficient way to do it, but it works. Just get rid of any decimals and decimal points first, then wipe out the non-numeric characters in a two step function. function numbers_only($string) { $decimals = preg_replace('/\.(\d{1,2})/', '', $string); return preg_replace('/\D/', '', $decimals); }
  2. If anyone could help with this it would be greatly appreciated, I still haven't grasped all the intricacies of regex yet. Here is my current function, to strip out any non-numeric characters from a string and return the cleaned up string. function numbers_only($string) { return preg_replace('/\D/', '', $string); } I run into problems, however, when a number such as $5,000.00 comes into the function. It returns 500000 instead of 5000 as desired. I know what I need to do (only grab the string data from before the '.') just not how to do it exactly. Thanks in advance.
  3. That's what I was looking for. I'm actually working with a pre-done system so the data was already formatted in a bunch of other places in the script which I didn't want to mess with. Your code above did the trick, I forgot about str_replace, thanks.
  4. Hello: I'm sure this is an easy question for most of you, but is causing me problem for some reason. I need to add two numbers together, both of which are already converted to a string for other uses. Meaning the first number is "3,000" and the second could be "1,500" (notice the commas). If I try to just add them it doesn't correctly show '4500' like I need, I suspect it has something to do with the commas that are in the string. Any thoughts? Thanks!
  5. Got it, but let me throw out a solution and see if it's possible? What if the script already had a total line count from the CSV file (which it determines during a normal import). Is it possible to use some function to utilize this 'total linecount' number to read from that specific line only (which would be the last line of the file).
  6. Is there a way to read from the very last line of a CSV file that has been opened via PHP fopen() ? The trick is that this is a file that has been uploaded by a user, and opened by the server, but could have 100 lines or it could have 100,000. We just need to read from the very last line specifically of the file, which is basically a line containing an array of variables imprinted on the file during upload. Any thoughts on how to accomplish this? Thanks!
  7. Great link by the way, the functions on that page once you download them are very easy to use. That is exactly what I needed, although I was worried about moving away from Regex. Thanks much.
  8. Here is the situation I'm in, and where I'm stuck. Maybe someone has some suggestions for me. I have a script that visits a particular website search engine, and punches in a search term. The script already extracts the valid block of html data which is the raw results, in a specific table on the page. So, the data that displays on the scraper script is everything between these <table> tags. What I need to do is grab the information from a specific column on the table, between the <td></td> tags. The trick to this problem is that I'm guessing most of you will suggest to run regex on the results to capture everything between <td></td>, however, I typically ONLY need the first column or second column of data. Is there some way to have regex or some other function loop through my results, then find the </tr> or </th> tag, which then triggers is to only extract data from the NEXT <td> </td> cell. This is the only way I could think of to identify the location of a 'first column' cell, because there is no special style attribute or any other identifier in the <td> tag. Any suggestions?
  9. What happens to the $data variable after that line of code?
  10. Just in case anyone bumps into this post I thought I'd elaborate on what I ended up doing. There is a nice set of functions that I'm sure most of you know stored in the prototype.js library. One in particular called Ajax.updater. It enabled me fairly easily to post the data from my form onload() through javascript, and then run a .php script externally from the post data. When finished loading it updated the results in a DIV on the page. Good stuff.
  11. No, I was just asking Although, that script doesn't really accomplish or fit with what I'm doing, but I get the jist of what you're saying. I already have the scraped content stored in a string variable, nicely filtered, and I would need to ADD a partial string to the beginning of the HREF tag rather than just cycle through and replace all of them. I suppose I'll have to read up more on DOM, thanks for your help.
  12. I'm using regular expressions to scrape the html I want to begin with, as from what I understood it is the fastest way. Wouldn't the output need to be converted to XML first, and then run through DOM parameters? It seems like a very indirect way of doing it with some unnecessary steps, but then again I'm not really sure...
  13. Hey all, I've run into a little problem with a script I've been working on. The script grabs a bunch of HTML from a separate web page, and then displays the results onto my page. I have already put in some basic filtering using the strip_tags function of PHP so that only A TR TD TH and P are allowed as HTML tags when the code is put in. However, my next step is to convert the links that are coming back to a specific absolute URL prefix. For example, the links are being returned as <a href="/test/blabla.html">text link</a> which is accurate to how they are on the page the URL is grabbed from. However, I need to loop through all the A tags and add a direct URL before the HREF so that the links actually work when clicked. If they are left as is, the link behaves as if that URL is located on my page, which it isn't. I guess my question is, is there a simple function to accomplish this feature in any of the major PHP frameworks or in the core PHP code that I have missed? I found some long code examples on how to accomplish this but I was hoping there is just some simple function I can use instead that might be easier. Thanks!
  14. So I guess the solution would be to load the PHP functions via javascript directly on the page. I'll have to read up more on AJAX as my usage of it so far has been limited. I know the theory and the usage just haven't actually utilized it very much.
  15. I have written a script that scrapes a few of our partner websites and displays various sections of their content directly on the page where the script is running. The script works fine, and is grabbing the content perfectly, but what I'm looking to do is optimize it so that it will actually load the page and display some 'Loading...' animations while the actual scraping operations are running. I'm assuming I could put the scraping operations possibly in some external .php files or something to that effect. Is that the best way of attacking this issue or am I overlooking something? I guess the end result that would be perfect is to have the basic HTML of the page load first, and then have the PHP operations running in the background... Also, I'm wondering if anyone who has experience with these types of scripts knows of any better way to grab html content off various pages. Curl seems to work great, just curious if there are any other options that are faster or more efficient.
×
×
  • 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.