Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. right, since it's run on linux, but you're opening the file in windows notepad, well windows notepad won't recognize the linebreaks. Most "real" code editors like html-kit, etc. will automatically convert it for you so that you see it the way it should. Also, certain programs like excel are smart enough to make the conversion. But I know for a fact that regular notepad isn't smart enough to do it. The safer thing to do would just be use "\r\n" (make sure it's in double quotes so php will treat it as escape chars) instead of PHP_EOL. Linux will ignore the \r and windows will read it properly. This will mess with some other systems for example older macs but you can probably not care about that.
  2. also FYI, php does have csv handling functions fgetcsv for reading and fputcsv for writing. You should use these instead of fwrite since they account for and escape embedded delimiters (quotes and commas). Also want to mention that I'm not sure your logic is correct.. you have a .= operator for your $content so it's appending the previous row to the new row and then your file handling is also in your while loop so you're basically creating an aggregated list like this: a ab abc abcd abcde Actually with the newlines, it'd look more like this: a a b a b c a b c d a b c d e I doubt that's what you want.. so you should either change that .= to = or else move your file handling outside of the loop.
  3. PHP_EOL is defined for the system the script is run on. So if you run it on a linux system, it will be defined as '\n'. If you run it on Windows, it will be defined on '\r\n'. So if you run it on a linux system and then open it as-is on a windows system, you aren't going to see the line breaks.
  4. use an anonymous function if you really wanna go for cramming 1-lining it: print_r(array_uintersect_assoc($array1,$array2,function($a,$b){return $a>$b;}));
  5. I wouldn't bother with validating if it's a real number. Best case scenario is you validate against known reserved numbers and some current ranges, but it's an ever-changing list so you'll always have to keep that info up-to-date. Also, that doesn't account for people who could lie about their phone number with a perfectly valid number. As Psycho mentioned, easiest thing to do is just strip out all non-numbers and count how many numbers there are. If you already know it's supposed to be a US phone number, then expect 10 digits. If it's among a list of international numbers, expect 11 digits. Usually someone can just use the last 7 digits when calling someone locally (like next door neighbor) but nobody in their right mind hands out their phone number without the area code (the full 10 digits) unless it is to their neighbor. Don't bother accounting for extensions. An extension can be literally any number. If you want to receive someone's extension, make sure it's received in a separate field. If by some chance you are having to work with a list with them already in it, then there's no official format for it, but "usually" people separate the main number and the extension with some variation of "x" "ex" or "ext" (which may or may not have a dot at the end). Best I've come up with (which I've mostly never had issues with, but isn't guaranteed 100%) is before stripping out all non-numbers, I look for first letter char and strip it and anything else after that. This is because there is absolutely no convention for having letters in a US phone number except to someone note an extension. So overall, this is what I usually do: $number = preg_replace('~[a-z].*$~i','',$number); $number = preg_replace('~[^0-9]~','',$number); if ( strlen($number)==10 ) { // valid US number, woo! } else { // fuck this noise } If you really, really need to ensure it's a real working phone number and hopefully associated with the person giving it (e.g. they are signing up for a paid-for service and if they fail to pay, you need to contact them and threaten to break their legs), I would suggest using a paid 3rd-party service that will verify a number and return info to match against other info entered in (like the person's name, address, etc.)
  6. a lot of it depends on the server you are making the request to. If it has mechanisms in case to prevent bots, you may need to do things like fake user agent. Or if it's a secure (https) url, you'll need to set options that either handle or ignore SSL certificates and stuff. Look at the list of curl options from the link catbeagle supplied. You can also make use of curl_error() and curl_errno() to get some clues about what's going wrong.
  7. I'm not terribly versed in ASP either but based on his ASP code I think this one should be set to true: curl_setopt($curl, CURLOPT_POST, true);
  8. you're going to need to use cURL for this.
  9. Not sure how you expect us to help you without posting any of your code or a link to the page in question.. providing some links to code you've tried doesn't help us help you. Also, saying "it doesn't work" doesn't really help us help you. You'll have to try and be more specific. On a side note, have you considered submitting your form via AJAX, so the page doesn't have to reload at all? That way you won't even need to worry about remembering scroll position.
  10. You need to implement an analytics tool. The most popular free tool is Google Analytics, but there are a lot of other options. Google "web analytics tools".
  11. frameworks like jQuery are built specifically to make things as cross-browser compatible as possible. If you are using jQuery and it doesn't work (make sure you are using the latest version), then it's a limitation with IE, not jQuery (javascript). But, you're using a jQuery plugin, which isn't the core jQuery library. It's possible the plugin has a bug. Also, most popular jQuery plugins will list any limitations/caveats with various browsers; you should check the carousel documentation to see if it lists anything. Of course, it's always possible that you just didn't implement it right, but I echo Irate's sentiments: not gonna spend forever sifting through a ton of code. You'll have to make some more effort to narrow it down a bit more if you want free help.
  12. We can't really answer that. Firstly, it depends on your needs, and even you won't get a good feel for that until you just pick one and go for it and get a few projects under your belt and then review the situation to see if what you picked works for you. A good chunk of that decision will probably boil down to personal preference, e.g. whether or not you like the look/feel of the tool, even if it functions according to your needs. It's like asking what car you should buy.. virtually all cars will get you from point A to point B so there isn't necessarily a "best" option. But, depending on your own personal situation (e.g. - projects, personal taste, etc.) one might be a better fit for you. Notice the keyword here is "you". Only you can really determine which is the best tool to use. I could tell you my own personal PoV from my own personal experience for these types of tools, but that's not going to really helpful to you. But for shits and grins I'll share my experience anyways, let you decide for yourself how useful this info really is.. First off, I don't actually admin any of these things, so I'm restricted to what my employer gives me access to. So it very well could be that some of these tools can do a lot more than I know about. basecamp - personally I think it sucks. AFAIK there's no kind of code integration with it (e.g. git/svn). It basically lets you easily setup adhoc todo lists and enter in a date/time spent for each one. IOW it's little more than a time tracker. At least, that's the impression I get out of it, and pretty much all I've ever used it for. jira - this is supposed to be a really good project management solution. I have lots of clients who use it and consequently I have to login and use their instance a lot. My main impression is "too many bells and whistles, too complex." This may turn out to be awesome if you have HUGE projects, but if you're just sticking to small projects or basic time management, it just seems too much IMO. But it seems to be really popular amongst the dev crowd because of code integration. github - I have very little experience with this, but we're fixin' to start using this at my work (currently we just have an svn repo on our server). My coworker says it's great. It's supposed to be less complex than jira, and in general cheaper. This one also has code integration. attask - I have to use this one fairly regularly as well. I kinda get the same impression from it as I do with basecamp, though I only have very basic level access to it. I hear from the uppers that it's significantly better than basecamp as far as project/time tracking, but afaik there's no code integration with it.
  13. Alternatively... $arr = array(15, 10, 25, 419, 65, 25); arsort($arr); echo key($arr);
  14. $arr = array(15, 10, 25, 419, 65, 25); echo array_search(max($arr),$arr); note that if the max number appears more than once, the first matched index will return. You didn't really mention what should happen in this event, but if you need all of the indexes for the highest value then you should use array_keys instead. And if you need the last index, use array_keys and then array_pop.
  15. oh. I came in here thinking I was gonna get a present or something.
  16. I agree that in general a DOM parser would be better for general DOM parsing/manipulation, but regex isn't a bad alternative if what you are looking for is regular. If that is all you want, this regex should work ($anchors will hold the results): preg_match_all('~<a\s+.*?</a>~is',$string,$anchors); If however you want to parse individual attributes or just the "text" of the anchor etc. then using a DOM parser would definitely be better. since you are using regex buddy, <a\s+.*?</a> is the actual pattern and is are modifiers for making it case-insensitive (i) and also allowing the dot to match newline chars (s), in the event that the "text" inside the anchor tags has newline chars (so IOW make sure to add those flags in regex buddy)
  17. Well tbh I don't have much experience working with double-byte languages (never really been needed for my job) but I do know that for the regex you can use the u modifier to put the regex engine in utf8 mode. There isn't a utf-16 version though (that I'm aware of) .. As far as reading the file, here is a comment in fgetcsv entry that might help. Actually, this comment might be more useful to you, since it mentions utf-16 specifically.
  18. at face value, there is nothing wrong with the code you posted. Canned example: $fp = fopen('test.txt', 'w'); fputcsv($fp, array("^\s")); fclose($fp); $fp = fopen("test.txt", "r"); $data = fgetcsv($fp, 1000, ","); $pattern = $data[0]; $xmlElem = ' foobar'; echo $pattern; // outputs ^\s echo preg_match('/'. $pattern .'/', $xmlElem); output: ^\s 1 There must be more to your code than this.. What I do find odd is how you say this works: preg_match('^\s', $xmlElem) - when you don't have a delimiter in that pattern..
  19. I've used them as a registrar for years without problems. I've never used them as a host though. Instead of just saying they suck, how about saying why they suck.
  20. It works fine with Ch0cu3r's fix: http://jsfiddle.net/pDHZ6/1/
  21. @njdubois I see your "But my code worked fine before" and raise it with this: Godaddy has a LOT of people who host their site with them. If it was a problem on their end (and I'm not saying it's not), then surely there would be others complaining as well? I am not necessarily disagreeing with your assumption; if it were me, I'd be making the same assumption. Actually, if it were me, I'd be hard pressed to not write it off as being the downside to shared hosting. You have no idea who else is using what resources and when. But the difference between you and me, apparently, is that "probably" isn't good enough for me. I've lost count of how many times I've seen on these forums threads opening up with "My code worked fine before, and I didn't change anything, and now it's not working," or similar. All I'm saying is you need to absolutely, not speculatively, rule out whether or not it is your code acting in whole or part of the problem. Especially if you decide to do more than write angry letters to Godaddy (e.g. take it to court). You know what they say.. assumption makes an "ass" out of "u" and "me". But in any case, if you are so certain that it is not in any way your code, and the problem must be on Godaddy's end.. why stick with them? Find another host and be done with it.
  22. please provide code example of what you mean
  23. It doesn't work because that's not how jQuery.load() works. .load() makes an ajax request to load a script, though there is an optional 3rd argument to specify a callback function when it has completed. Basically, there is no way to check if an image has been loaded or not, unless you specify a callback before the image is loaded. Example with creating image via js: var img = document.createElement("img"); img.onload = function() { alert('loaded okay'); } img.src = "http://www.google.com/intl/en_com/images/logo_plain.png"; document.body.appendChild(img); In this example, you can see that I have defined an .onload callback function (which should be defined before img.src is set, because the browser attempts to download (load) the image as soon as this is set). Same principle with an image tag, you can add a callback to the onload attribute: <img src="http://www.google.com/intl/en_com/images/logo_plain.png" onload="isLoaded()" /> <script type='text/javascript'> function isLoaded(that) { alert('loaded okay'); } </script> So basically, there are ways to attach an event handler to trigger when something is loaded, before it is loaded, but there is no way in javascript to determine whether or not it loaded, after it has already loaded. IOW there is no "isLoaded" type of property or function. Why not? I honestly don't know, and it's actually kind of annoying. If you have a browser addon like firebug to see the actual request and response, you can see if an image returned a 404 or timed out or something, so it's not like the browser doesn't know. It really doesn't seem like it would be that hard to expose that info to javascript. And it would be really useful, especially as far as making sure asynchronously loaded js scripts are executed in proper order. For scripts you can at least keep checking for the existence of some variable or object that's unique to that script (though you have to decide for yourself how long you should keep checking, since as I said, there's no way to know if it failed to load or is still loading or what), but there is no such work around for images.
  24. To be more clear, nobody replies because replies have been disabled in that forum; read the stickies there for info about the rules/procedure for posting there.
×
×
  • 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.