Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. <input type="text" name="name" id="name" value="<?php echo $_POST['name']; ?>"> etc...
  2. would the internet be such a terrible place if that were enforced?
  3. xylex: your argument is akin to saying there is nothing inherently wrong with coding a site as entirely static html. It is true, there isn't. But if you want any kind of flexibility, ease of use for expanding/updating, etc.. it is not a good idea to code everything static. The same principle applies here. In and of itself making it global is not bad. But the point is, there's really no good reason to use it, either, because in practice it's better to do it other ways.
  4. function getPhraseCount($string, $numWords=1, $limit=0) { // make case-insensitive $string = strtolower($string); // get all words. Assume any 1 or more letter, number or ' in a row is a word preg_match_all('~[a-z0-9\']+~',$string,$words); $words = $words[0]; // foreach word... foreach($words as $k => $v) { // remove single quotes that are by themselves or wrapped around the word $words[$k] = trim($words[$k],"'"); } // end foreach $words // remove any empty elements produced from ' trimming $words = array_filter($words); // reset array keys $words = array_values($words); // foreach word... foreach ($words as $k => $word) { // if there are enough words after the current word to make a $numWords length phrase... if (isset($words[$k+$numWords])) { // add the phrase to list of phrases $phrases[] = implode(' ',array_slice($words,$k,$numWords)); } // end if isset } // end foreach $words // create an array of phrases => count $x = array_count_values($phrases); // reverse sort it (preserving keys, since the keys are the phrases arsort($x); // if limit is specified, return only $limit phrases. otherwise, return all of them return ($limit > 0) ? array_slice($x,0,$limit) : $x; } // end getPhraseCount //examples: getPhraseCount($string); // return full list of single keyword count getPhraseCount($string,2); // return full list of 2 word phrase count getPhraseCount($string,2,10); // return top 10 list of 2 word phrase count Description: Okay, so basically this function will take the string and return a phrase => count associative array. If you only pass it the string, it defaults to doing a count of individual words and returning all of them in descending order. Optional 2nd argument lets you specify how many words in the phrase. So if you put 2 as 2nd argument, it will go through and for each word, take the word and the word after it and count how many times that 2 word phrase occurs, returning the list in descending order. If the optional 3rd argument is used, it returns top x amount of words, so like 10 would return top 10 phrase occurance. Limitations: - hyphenated words are not matched. - case in-sensitive. - assumes $string is "human" readable text. In other words, if you were to pass a file_get_contents of some webpage to it, you should probably strip_tags first, as well as do some regex to remove stuff between script tags, etc...
  5. read the user notes in readdir or scandir there are several user contributed functions that show how to recursively grab files/subdirectories.
  6. date does not require a 2nd argument (defaults to current timestamp), but the 2nd argument is expected to be a unix timestamp. You are passing "09" to it, so it's looking at that as the entire timestamp. you need to use mktime to fill in the rest of the timestamp: $month_short=date('M', mktime(0,0,0,mysql_result($result,$i,"month"),0,0));
  7. only american sites eh? TERRORIST!
  8. You're missing the point about globals. The problem with using them inside functions is that they transcend the scope of the function. The problem with this is that now you cannot 100% guarantee that the function is going to do exactly what it's supposed to do every time, because there is now something outside of the scope of that function being used inside it. The whole point of functions and even classes is to abstract certain things out of everyday programming. Well in order to do that, you have to be confident that those abstracted pieces of code are doing what they are meant to do 100% of the time. When you do not respect scope, you can no longer be 100% certain that issues are not within those abstracted pieces.
  9. Are you sure that's what you are getting from the form? Echo out the $_POST var. Alternative to date() would be to explode at the hyphen and then just reorder the elements manually. $string = explode('-',$string); $string = array_reverse($string); $string = implode('-',$string);
  10. date
  11. so use a condition to see if a result is returned. If so, use the function. If not, do something else. For instance, initialize it as an array if no results returned, so that array_intersect won't throw an error.
  12. you would not be able to copy/paste the upside down text unless the user has a specific font for it on their own computer. So you may as well forget that. Easiest thing is to follow the tutorial in the link. One of the functions used in it has an optional argument to set the angle of the text. It is briefly mentioned in the tutorial. Go to the manual entry for that function to learn about it.
  13. you forced a hobbit to do what....?
  14. http://www.phpfreaks.com/forums/index.php/topic,228009.0.html
  15. yes, they are referring to register globals being removed. But FYI what you are doing is also bad coding practice.
  16. we ARE. http://www.aspfreaks.com/ bastards MUST GO DOWN.
  17. file cannot read the content of a variable. If you already have the file contents in a variable, you can follow mjdamato's route by using explode with "\n" as the delimiter. Then loop, etc.. if you want to go the regex route, you can take your variable that has the content and do this: preg_match_all('~vcalendar: start(.*?)vcalendar: end~is',$content,$matches); $matches[1] will be an array of each set of lines between the start and end. I don't know what your overall goal here is, but from there, you can do something like this: foreach($matches[1] as $k => $match) { $descriptions[$k] = array_filter(explode("\n",$match)); } This will give you a multi-dim array that would look like this: Array ( [0] => Array ( [1] => somedescription: some value [2] => somedescription: some value [3] => somedescription: some value ) [1] => Array ( [1] => somedescription: some value [2] => somedescription: some value [3] => somedescription: some value ) )
  18. example of file/content?
  19. It's "dateline" that's what it's called. For real. I asked a real editor. He used to be chief editor of several major Newspapers around the country, been doing it for the last 30 years. Conversation:
  20. Yeah well...in the real world, most people don't have time to make stuff perfect. I've got too much work on my plate on any given day to make sure all my t's are crossed and i's are dotted. If what I do works in most major browsers, as far as I'm concerned, it's good enough. I promise you, the people with the money who make the decisions don't care one whit about that sort of thing. As long as they can go to the site and it looks pretty and does what it's supposed to, it's all good. I'm not necessarily promoting bad coding...I'm just sayin'...when you have 500 things to do, you have to prioritize. Which is why I lean towards "breathing room" regexes etc.. because I know most other people out there outside of the classroom are under the same pressures, and therefore do the same thing.
  21. If we are going to count computers owned that aren't in use, I have about a dozen or so old computers that technically work but they are very old and are just sitting in my garage collecting dust.
  22. that's correct. You will have to loop through all of the rows and store a running total in a separate variable to get the total for the 'column'
  23. In my house, I have a desktop and a laptop. Wife has a desktop. Brother has a desktop and laptop, though he hardly uses his desktop anymore.
×
×
  • 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.