-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
text-to-column is a data operation in excel. It's basically a wizard for letting you explode() at a specified delimiter, and put the exploded values into their own columns. Unless you've customized your menus, if you go to the "data" tab, in the 4th group you can see "Text to Columns" "Remove Duplicates" etc.. Example: in A1 if you have "a,b,c" and highlight column A and press the Text to Columns icon, it will bring up a popup wizard. You specify your delimiter, and it separates "a,b,c" into 3 separate columns so that "a" is now in A1, "b" is now in "B1", and "c" is now in "C1". As far as excel automatically converting an opened file... I can open a .csv file just fine in excel and if it is properly formatted, yes it puts things in columns, but if I do not have it formatted with quotes around columns, it puts everything into a single column... perhaps there is some kind of setting I do not have checked, that automatically converts or something..but that doesn't work for me...will check that out..
-
hmm...then you must have more to the string than you've mentioned, or else you have some other code not working properly. $string = "2 0 7 1 1 7 1 1 6 8 7"; preg_match('~((\d+\s?){3,}).*\1~',$string,$matches); $number = $matches[1]; echo $number; that echo's "7 1 1"
-
$string = "12 5 6 12 5 7 8 7 5 7 8 7 3 21 12 5 6"; preg_match('~((\d+\s?){3,}).*\1~',$string,$matches); $number = $matches[1];
-
Okay, one more question...do the numbers have to be next to each other? eg: 1 2 3 1 2 3 vs. 1 2 3 4 1 2 3
-
3 or more or exactly 3? I hope you are seeing a theme to my questions here...be more specific in what you want
-
okay so back to my original question, are TWO numbers considered a repeated pattern, or does it have to be a minimum of 3?
-
now wait a minute, that's a different pattern.. "1 2 3" is *a* pattern in that it is sequence of numbers with the same incremented value, but "1 2 3" is not the same pattern definition as "7 8 7" in your example. In my example, "1 2 3" is not repeated...
-
what do you consider a repeated pattern? 1 2 3 1 2 4 is "1 2" considered a repeated pattern?
-
My assumption is that in order for him to do that, he's having to for instance in excel perform a text-to-column operation with comma as delimiter, and just hope that the values themselves do not have commas (though he knows his data better than us, it is possible that he knows his data will NOT have commas in it). But the overall point is he asked to make a CSV file. Just dumping the existing format in a file is quick and dirty, yes. But it doesn't make for a valid CSV file. If he were to open it in excel, he would still have to perform a text-to-column operation, and if it were some other script expecting a CSV format, it would not work; the column values are not wrapped in quotes, so the script (just like excel, until you perform the text-to-column operation) would treat the entire row as one column.
-
That is not a valid CSV format. Column values need to be wrapped in quotes, and commas and quotes that are part of the column values (if there are any) need to be escaped.
-
Well, whether or not it is a terrible idea depends on what he's wanting to do. If each table is just going to be something like profile info or the like...then yeah, its a terrible idea. But anyways...all questions of "why" aside...OP, you have stated what you want/need....and? What have you tried? Is there a particular bit you are stuck on?
-
In the OP the stated problem is to specifically create a csv formatted file, not *a* file with data dumped into it. Sure, he *might* for the most part have little trouble taking the data format as-is and making it work elsewhere...maybe...for example, if he were to open it up in excel he could do text-to-column operation and split at comma and that will work, assuming his actual column values will never have commas in them...but that's assuming that the file is going to be used for that purpose. He may very well need it for some other script that expects a csv formatted file (he does mention having to export after c/ping) and then your method will not work at all. Since your suggestion does not solve the OP's issue, how easy/simple it is, is moot.
-
@ManiacDan: Yes, you can use file_put_contents to write to a file but that's only really useful for writing literal data. In order for him to create a csv file he's going to have to first format all the data to be csv format, before he uses file_put_contents .. which is not necessary, because that's the point of using fputcsv - this function formats the data for you. @obydesign: Did you look at the example in the manual entry for fputcsv? Was there any particular bit that you need clarification on? Basically you need to create the resource handle for the file you want to output to (same way as you created a file resource for the file you are reading in your script, only for a file to write to). Then in your for loop, instead of (or in addition to) the echo, you need to make an array out of that line of data. You will then call fputcsv with the output file resource handle as first argument, and the array of data for the row as the 2nd argument (the row data (2nd argument) is expected to be an array (so do not use implode)). Each value in the array should be the actual data you want for each column (do not wrap it in quotes or anything, unless quotes are literally part of the actual column value). // somewhere at the beginning of your file, before the loops... $outputFile = fopen('outputFileNameHere.csv', 'w'); // I assume this is the loop you are wanting to write data.... this is what your loop should look like... for ($c=0; $c < $num; $c++) { // turn that giant echo into an array... $row = array("admin","base",$data[2] ."-Small-Satin-No Frame", etc...); // write the row to the file... fputcsv($outputFile, $row); }
-
php does not have multi-threading capabilities. closest it has is forking which isn't exactly the same thing. One alternative is to write a separate script that does nothing but the system command and have the arguments pulled from a flatfile or something, and this script here just update the flatfile with the command to run. And then set the other script that's actually running to be on a cron job every minute or so and look for the command in the flatfile, run it and then delete the line from the flatfile (so that next time it is run it won't run the system command). IOW basically a queuing system for the system command.
-
Getting the clicked element in an onclick handler
.josh replied to jhsachs's topic in Javascript Help
"this" refers to the the invoked object. When you click on a link, "this" refers to the link object, but when you call a function within the onclick attrib and the function is running, you are no longer within the scope of the link object, so while the function is running, "this" refers to the function. So as DavidAM pointed out, you must pass the link's object to the function as an argument to the function, so that you can refer to it in the object. -
No, what is abundantly clear is that you are making assumptions about a lot of people around here whom you know next to nothing about. How do I know this? Because I do know most of the regulars here, either personally, professionally, or both. For years. I can't speak for the random one-post-wonders though, so if those are the people you are referring to, then by all means, keep on with your assumptions about them, if that's what "works" for you. And I did not disagree with you on that count. In fact, I made it a point to explain that I did agree with you on that, but also pointed out that you are perfectly able to follow the advise given and still consider web standards and accesibility issues. Now you're just playing word games. Be straight forward. Either you know their opinions or not. You are entitled to your opinions but you can't expect me to listen to them when you're just making assumptions about what you think other people will say. Then why did you even bring it up and ask for advice on the matter? Are you just trolling? Because I can't think of any other reason why you would ask something if you already know how to do it. I'm not trying to sound patronizing, but this is the internet, you type things out. This isn't face-time where you just blurt things out because you're distracted and then be like "well shit.." I'm not asking you to be perfect with your words, but I do expect you to be accountable for them. If what you say is true, then fine, but know that you got your responses based on your own faulty wordings. Say what you mean and mean what you say. In general, fair enough, but again I must point out if this were really true, you wouldn't have asked for the latter. So either this statement is untrue, or you're trolling. Do you have a 3rd reason? Does this fall under the "I was hungry, didn't speak what I meant" excuse? Which items were not the best choices? Are you still going on about using a particular color (red)? Because if so, you entirely missed the point. They were examples to convey principles. I even pointed it out as such in my original post...for instance, I would never put css markup in-line like that. It was an example, get over it. Yes, yes you do. Nobody has said otherwise. And I have rights to voice my opinions, too. And my opinion is that you don't understand half the advice given to you, made assumptions about the other half, and for some reason are trying to argue about it even though you yourself acknowledge these are all opinions, and I myself have repeatedly acknowledged that you can do whatever you want and if it works, it works. The way I see it, you keep asking for advice on stuff you claim you already know the answer to. Cite questionable sources (sorry, saying "I think a bunch of people would agree with me" is questionable), tell us we don't know anything about said subject matter as if you actually know us... at this point in time, I'm inclined to agree with xyph that you really are trying to pick a fight here. And this isn't the first time you've been through this song and dance with people around here, have you? Yes, I've seen your previous threads, and I have tried real hard to defend your rights around here. You do everything you've done here...you start off asking some questions, then write the answers off as if you already knew they were wrong, point at vague evidence about why it is wrong, and then get all pissy when they lash out at you in frustration. But I have nonetheless repeatedly defended you over it, because yes, you are entitled to your opinions. And you are entitled to being a dumbass who simultaneously calls someone an expert and asks for help, and yet dismisses them as being clueless. It is your right to be that person who asks for help and refuses to listen. You don't know. Everything you know is your opinions and what you think "others" would say. You have shown me nothing more. You may look like an expert to your "non-techie" clients as you put it, but that don't fly around here. We don't expect you to bow down to us like we're gods. What we do expect is for you to not yank our chains like you know wtf you're talking about when you know damn well you don't. You don't bullshit the mechanic about how you think a car should run, and you don't bullshit the professional web developers about how things should be done on the web. The fact that you think it is even possible to know jack shit about one piece and be expert on another proves what a noob you are. And it is fine to be a noob. What is not fine is the attitude. Ditch it or GTFO. And if we are as worthless as you think we are, then you aren't going to miss out on anything.
-
I mean, as you say, this is a php site, so what would we know about it? And as you say, you know a ton of web designers. And as you say, they would probably agree with you. I'm not really sure what you mean by "probably"...can you help me out on that? Does that mean you polled them and they haven't decided yet? Or are you just making assumptions about their opinions? Can you please clarify what you mean when you say that you know a ton of web developers who will "probably" agree with you? And if their "probable" opinions outweigh some random people on a php site, why are you on a php site asking for help on this topic?
-
You don't need to know javascript for this task. You need common sense and basic editing skills. If you want someone to do it for you, post in the freelance forum. If you want a nudge in the right direction because you are trying to learn something, post here.
-
<script type='text/javascript'> var urls = [ 'http://cvs.com', 'http://target.com', 'http://walgreens.com' ] function next() { this.c = this.c+1 || 0; if (typeof urls[c] == 'undefined') window.location='http://somesite.com'; else window.frames['links'].location.href=urls[c]; } </script>
-
I don't misunderstand you at all DoubleDee. We just have different opinions, based on different things backing us up.
-
I don't deny what you are saying, but I am very 1990's and so far my website uses NO JavaScript and it looks and runs better than those that do IMHO. You are entitled to your opinion, same as me. I don't necessarily disagree that it would "run better" without javascript in the sense that it would technically run faster, since you don't have that overhead. "Looks better" is certainly a matter of opinion and at the end of the day, neither of our opinions really matter, it's the client's opinion that matters (though if you ARE the client, then well..there you have it ). Fair enough, but red is just one color out of many...and it's just one markup out of many... You can certainly pick "more accessible" color/markups and follow the same principles... I'm sure you can find many web developers who keep things like accessibility in mind. But web designers/developers who throw out javascript completely? Sorry, but no modern web developer should do that. Even my biggest name clients who literally spend millions of dollars on web design, UX efforts, etc... do not care about non-js users, even for their mobile sites. As I mentioned, I do web analytics for a living. I see the numbers from sites, big and small. I see the decisions made by those numbers. You say you know a ton of web designers who probably agree with you...I have cold hard numbers backing up my opinions. I mean no offense, but you are stuck in the 90's on that count, lol. But at the end of the day, it is just opinion. To each his own. If you are makin' people happy and makin' a living off it, who am I to say it doesn't work for you?
-
If you do want a no-js no-popup friendly version...well technically it can be done, but it will involve putting the logic server-side and outputting new content dynamically. This increases requests to your server, bandwidth consumed. The "better" no-js/popup route would be to stick to having the messages output in-line and work on making the message shorter, fit in with your overall design, as you have been doing. But IMO...this isn't 1990. Very few people actually have javascript disabled. I would advise you not to care about people who have javascript disabled. I work in the web analytics business. I look at numbers like that all day long. But take it as my own opinion, nonetheless. And we're not talking about actual form validation w/ js...just the format/aesthetics. If you want to move forward with doing it w/ JS, the "how" is kind of page-specific. If you have a framework like jQuery on your page, there are a lot of (relatively) super easy ways to add this sort of thing. But it basically boils down to having a js wrapper function called in an onclick attribute, which appends a css positioned/marked up div in place. I would suggest asking for help on that in one of the other forums (html/css/js) if you wanna go that route though, because it's kind of a separate topic from regex
-
well then you could mark them up in a special format to "delimit" them (eg: different color, in bold, etc...). crude example to get my point across: $errors['username'] = 'Username must be 8 to 30 chars and only contain letters, numbers, or the following chars: <span style="make bold or colorful css rules here">_.-</span>';
-
I personally like to do the error msg even more generic like "Username is invalid" or highlight the form field red or something, and then have a ? icon of some sort and when the visitor clicks (or hovers) on that icon, it gives a popup with the details, and the popup is not "in-line" so you don't have to worry about it breaking the flow of the rest of your form or w/e. Which is present and available to click at all times (before visitor attempts to enter username, or after, if it fails [pre] Username: [ ] (?) [/pre]
-
I mean I get what you're sayin' here: But IMO there's no reason to list out the non-alphanumerics. I'd personally do : $errors['username'] = 'Username must be 8 to 30 chars and only contain letters, numbers, or the following chars: "_.-"' ...and add to the non-alphanumeric list as it grows.