-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
As well as what cags is asking, will the string always end with " Players" ?
-
What search phrases have you been using?! The PHP manual pages for strtotime and date functions are right at the top of the list of results for anything like "strtotime to date" and such.
-
some questions just for my own knowledge
salathe replied to chaiwei's topic in Other Programming Languages
The SPL comes in very handy once you start delving into the object-oriented way of thinking/coding. As an example, here are two ways of traversing the files in a directory: $dir = opendir('/path/to/some/dir'); while (($file = readdir($dir)) !== false) { echo "filename: $file : filetype: " . filetype('/path/to/some/dir/' . $file) . "\n"; } closedir($dir); $dir = new FilesystemIterator('/path/to/some/dir'); foreach ($dir as $fileinfo) { echo "filename: " . $fileinfo->getFilename() . " : filetype: " . $fileinfo->getType() . "\n"; } With the iterator there, we could very easily filter the results to show only files, files above a certain size, the first n files, files ordered by size, etc. by only changing the first line of code. With the opendir snippet, those things wouldn't be quite so neat and tidy. -
http://translate.google.com/translate_tools
-
Comparing two strings - Same letters, but different letter positions
salathe replied to gretorx's topic in PHP Coding Help
Really? strlen('pistachio')==strlen('phpfreaks')\ -
Comparing two strings - Same letters, but different letter positions
salathe replied to gretorx's topic in PHP Coding Help
Hmm; iguanodon, mongolian, pakistani, wednesday, lightning, magnetize, nostalgic, pistachio, millimole, scrapbook and unsayable (to name a few examples) all have the same ASCII number total (964) as phpfreaks. -
Take a look at pathinfo -- pathinfo("news.htm", PATHINFO_FILENAME);
-
There will be a cleaning van parked outside for long periods of time.
-
See: http://www.phpfreaks.com/tutorial/defining-a-php-function-only-once
-
So you just want to break the string into pieces at the relevant positions; or would it be more complex (are pieces optional, how do you get 555 from A, etc.)?
-
It seems a little strange that you just want to blindly insert the string but to get what you want, you can just do: preg_replace('/[a-z]+/', '$this->$0', $subject)
-
Dir Path, folders with names starting with n issue.
salathe replied to JMair's topic in PHP Coding Help
Or use single quoted strings: see http://php.net/types.string -
You really shouldn't be using string functions to access structured XML data, there are specialised tools for that. For example, you could do something like the following (which uses SimpleXML): $urls = array( 'http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/get_min_hit_list_bounty?user_id=100000952273457&target_id=100000556624340&level=358&session_id=8b56f9b52049dbe329b97c8293c7f78641ad7487&session_key=82573d27b16d6ea8ed2cc819a94c9d52dc93cd71&auth_key=cb07c7575b38df48d82dd53619385faa884db5a2&nocache=1272537280669&', 'http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/get_min_hit_list_bounty?user_id=100000952273457&target_id=100000556174477&level=358&session_id=8b56f9b52049dbe329b97c8293c7f78641ad7487&session_key=82573d27b16d6ea8ed2cc819a94c9d52dc93cd71&auth_key=cb07c7575b38df48d82dd53619385faa884db5a2&nocache=1272537280669&' ); // Loop over URLs, put min_cost numbers into array $counts = array(); foreach ($urls as $url) { $counts[] = (int) simplexml_load_file($url)->xml->min_cost; } // Find sum echo array_sum($counts);
-
He's right though.
-
New Forum Section - Quick Answers
salathe replied to cpawebmaster's topic in PHPFreaks.com Website Feedback
That would be the main problem; folks would copy/paste code expecting it to magically work for them which a lot of the time just isn't going to happen. -
Set the timezone before you use any function that will make use of it (e.g. time()).
-
New Forum Section - Quick Answers
salathe replied to cpawebmaster's topic in PHPFreaks.com Website Feedback
Even the "common" tasks that might be considered for a "pre-answered questions" style of forum vary enough that it would most likely be better to ask and answer the "same" question many times, specific to the needs of the asker. -
Is there any particular technical reason why that file must be on the work server? Including remote files is terribly inefficient, not to mention the security implications of passing the database credentials over the wire (assuming SSL isn't used).
-
The purpose of that function is simply to see if the magic quotes setting is on or not. Since magic quotes are a deprecated feature, the function is often used to see if magic quotes are enabled as a condition for code to undo its effect.
-
You could use the explode function which has a handy $limit parameter to limit the returned array to a maximum of $limit values. E.g. To get the two pieces that you want, you could do: $parts = explode(":", "Date and Time: Apr 26 2010 9:09AM", 2); print_r($parts);
-
You're very welcome. They're both super-useful tools that I make use of all the time. P.S. Welcome to the site, I hope you can stick around. Feel free to introduce yourself.
-
Bracket pairs can be used as delimiters, but are best avoided since they can cause confusion (as evidenced in this thread); acceptable pairs are (), [], {} and <>. As for what \D means, that has already been mentioned but a good place to look for that and others is on the backslash page in the PCRE regex section of the PHP manual. You could do [[\D-]] but see the note in my first paragraph about confusion! To match literal square brackets, escape them with a backslash character like \[ or \] (see the same PHP manual page I linked to above).
-
The site owner has decided to promote me to admin, there may be an announcement on the subject or the above posts might suffice. Absolutely; like any of the lassies here would fall for it! I'm also not too sure they would be flocking to see any photos of me but if you really want to put yourself out there, feel free.
-
It's the closest we've got so far!
-
It might be useful to look into using fputcsv which writes CSV formatted values to a file; if you need a string with the CSV formatted values, rather than writing to a file, there are ways to do that as well.