Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. Aside: array_slice(explode('/', $url), 0, -2) could be replaced with explode('/', $url, -2).
  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?
  3. 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
  4. It might help if you actually attached the file.
  5. Sure. Lets not get defensive, particularly when it's utterly off-topic.
  6. Likely not. Many people think that the short_open_tag is deprecated even though it never has been so. Its use is rather, discouraged.
  7. 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.
  8. 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.
  9. 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!
  10. 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.
  11. 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.
  12. No need to repeat what other people have already said. Thanks.
  13. 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.
  14. 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.
  15. 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.
  16. Someone didn't search before submitting a bug report. http://bit.ly/ipb-exp-ressions-bug
  17. 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.
  18. 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.
  19. 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)));
  20. $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.
  21. Thanks Philip and the others involved. Go team!
  22. Hi Michael, welcome back. PHP has changed loads over the years, best of luck getting reacquainted.
  23. The mbstring regex functions are only similar by name. They use the Oniguruma regex engine to get the work done, not POSIX nor PCRE. Only the POSIX family of functions are deprecated at this time.
  24. No, the mbstring regex functions are not deprecated.
×
×
  • 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.