-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
Great. Please post your findings such that others can learn from your mistakes.
-
I still do, daily. I'm a little stuck in the past.
-
As the others said, one of the easier ways would be to create an array containing enough information to sort the files as you need. This array could contain all of the information that you are going to display, or it could just be a stepping stone to getting the list of files in the right order: that's up to you. I would go with Barand's suggestion of creating an array mapping file names to DrawnDates. While you're here, there are a few minor points about your code that I hope you wouldn't mind me mentioning. The FilesystemIterator is preferred over the older, slightly quirky, DirectoryIterator. In your case, only the class name needs to be changed to use it. By using isFile(), the second condition will never be met: when $oFile is a file, then it can not be a dot-directory. Your code might as well be if ($oFile->isFile()) { Your XML files only have one DrawResult (judging by your example on Dev Shed), so there is no need to loop over (all one of) them.
-
I can't say I've noticed any particular issue today.
-
Remove Characters After Nth Occurence Of Symbol
salathe replied to matthewtbaker's topic in PHP Coding Help
Aside: array_slice(explode('/', $url), 0, -2) could be replaced with explode('/', $url, -2). -
Basic Latin characters (for example, A-Z, 0-9) don't count? Your example hints that they don't, but they're unicode characters too. Ahh, so it looks like you want the offset of the first character which isn't in the "C0 Controls and Basic Latin" table or perhaps some smaller set: just A-Z, a-z, 0-9? Which ones did you "find"? I am certain this task could be readily resolved with at least one of the available mb_* functions. Or with PCRE regex (preg_* functions), or regular string inspection and manipulation. What have you tried so far?
-
What you are doing is mysql_real_escape_string(p.categoryid) This is trying to concatenate the values of two constants, namely p and categoryid. Since neither of those constants exist in your script, PHP helpfully just takes their name as the string value. So it is concatenating the two strings, "p" and "categoryid", giving the resulting string "pcategoryid". This string is then passed to mysql_real_escape_string() to be escaped, resulting in the escaped string (nothing in this particular string needs to be escaped) of "pcategoryid" which you can see in your output. Now for some resolution; do you need to escape p.categoryid at all? It looks to me like you just want to write the column name directly into the query. where s.categoryid = p.categoryid
-
It might help if you actually attached the file.
- 4 replies
-
- javascript
- ajax
-
(and 3 more)
Tagged with:
-
Sure. Lets not get defensive, particularly when it's utterly off-topic.
-
Likely not. Many people think that the short_open_tag is deprecated even though it never has been so. Its use is rather, discouraged.
-
I wasn't insisting anything, you gave an incorrect example and I called you on it. Assuming anyone knows where to find the information available in the manual is a dangerous game to play, surely you have seen that by now. Your employers and school will love you, I'm sure. Following simple instructions and raising potential issues with the course content are not mutually exclusive. It's not "my way or no way", as you continually keep preaching here on PHPFreaks.
-
No. The short_open_tag directive is not deprecated; its use will not raise an E_DEPRECATED message. However, use of the short_open_tag has been discouraged for a very long time due to the XML conflict and many hosts having the directive turned off, but it is not deprecated. Not strictly true either. The default value, if none is provided in php.ini, is short_open_tag=On. That said, the "production" and "development" INI files that we distribute, and many third parties too, explicitly turn short_open_tag off.
-
And you'd probably fail the course because of that. The instructions are very simple and clear: follow them. If you're going to give an example of something that evaluates to false, at least use something that evaluates to false!
-
See array_diff. $arrTemp = array_diff($arrTemp, $arrMain) In this case, the array_diff() function returns an array containing all the entries from $arrTemp that are not present in $arrMain.
-
Have a look at http://json.org which shows how JSON should be structured in easy to follow graphical form. It is the array structure that you have.
-
No need to repeat what other people have already said. Thanks.
-
DateTime::createFromFormat() can be used to create a DateTime object from your variable. Then you can use format() to display it in another format, and diff() to get the number of "days left". To give you a basic example, putting the above to good use, lets take your original variable containing 2012-12-13 01:01:00 and do some magic. <?php $subject = '2012-12-13 01:01:00'; // Parse the subject date string as the given format $datetime = DateTime::createFromFormat('Y-m-d H:i:s', $subject); // Note, the above is a normal format that DateTime can handle automatically // so you could have done: (see http://php.net/datetime.formats and sub-pages) // $datetime = new DateTime($subject); // Lets get this DateTime object as another format // See http://php.net/date for what the format letters mean $reformatted = $datetime->format('jS F Y'); echo "Subject date is $reformatted. "; // Lets get the number of days between now and the subject date // Note: DateTime::diff() returns a DateInterval object, see http://php.net/dateinterval $now = new DateTime; $interval = $datetime->diff($now); $direction = $interval->invert ? "left" : "ago"; printf("That's %d days %s.", $interval->days, $direction); The above will output something like the following. Subject date is 13th December 2012. That's 63 days left. Have a play yourself, with a running example similar to the code.
-
Use a prefix, see the extract() docs. However, do you really need to extract those values into variables, more often than not it makes more sense to keep working with the array.
-
DateTime::createFromFormat() can be used to create a DateTime object from your variable. Then you can use format() to display it in another format, and diff() to get the number of "days left". Let us know how you get on.
-
Regexp Issue In Parsing: "expression" Gets Mangled
salathe replied to Christian F.'s topic in PHPFreaks.com Website Feedback
Someone didn't search before submitting a bug report. http://bit.ly/ipb-exp-ressions-bug -
And I'd butt out of the thread if not helping with the question posed. (Except for now.) It's not about "not using pipes", but rather being aware that sometimes it pays to put some thought into the delimiter character(s) being used if they are also used within the pattern.
-
Need Help With Loop And Date Incrementing Logic
salathe replied to rbemiller's topic in PHP Coding Help
Why not just change the SQL query to fetch only the information that you are wanting, rather than what you're not wanting? Of course, we can't help with your specific query until you decide to show it to us. -
Str/preg_Replacing An Array With The Same Words?
salathe replied to jimbbob's topic in PHP Coding Help
You can use the strtr function to replace the words without replacing the words that have been replaced. The only tricky part is creating the right array to feed into the function (the words that you want to be replaced should be keys, the replacement their values). A basic example looks like $text = 'Toyota is a car. Honda is a vehicle.'; echo strtr($text, array('car' => 'car,vehicle', 'vehicle' => 'car,vehicle')); Of course, typing out the array is not ideal so lets create that array from what you already have, by using array_fill_keys. $text = 'Toyota is a car. Honda is a vehicle.'; $synonyms = array('car', 'vehicle'); echo strtr($text, array_fill_keys($synonyms, implode(',', $synonyms))); -
$subject = '15.02.92'; $interval = DateTime::createFromFormat('d.m.y', $subject)->diff(new DateTime); echo $interval->y; The above uses the DateTime (docs) class (two instances of it; one for the current date/time and one for the date of birth) and a DateInterval (docs) object representing the interval between those two DateTimes. The DateInterval has several properties available including the number of years; which for our needs is the person's age.
-
Thanks Philip and the others involved. Go team!