Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. Hi chaps, What happened to the information beside each post with things like the poster's location, age, etc.? Currently it has been whittled down to just the post count, which seems like an odd choice. What's the score? Cheery-byes, Peter
  2. The freelancing forum is over there ---> http://forums.phpfreaks.com/forum/20-php-freelancing/
  3. The comma operator is a very esoteric operator, rarely seen out in the wild. I'm not surprised that you're surprised that it is valid. Its use is discouraged.
  4. This is trying, and failing, to get the position of the month name within the months string. There are two issues: first is that you're doing something weird to try and get the first three characters of birthMonth; second is that you're correctly trying to divide the string index by three (to go from string index to month number) but in completely the wrong place. Getting the first three characters of the birth month is easy enough with the correct syntax. birthMonth.substring(0, 3)Dividing the index to get a month number should happen only after you've gotten the index; not somewhere in the middle.var pos = months.indexOf(birthMonth.substring(0, 3).toLowerCase()) / 3;Finally, it might be worthwhile checking to see whether the user entered a valid month name. Otherwise, the pos is going to be rubbish.
  5. Change the order of SplFixedArray and NumericArray in your test. See what happens.
  6. The basic idea is something like: foreach ($data as $row) { include '../includes/Folder/' . $row['ref_filename'] . '.php'; }Hope that gets the ball rolling.
  7. You're almost there, just looping over the wrong thing. foreach ($cdata['MovieReviews'] as $movie_review) { echo $movie_review['MovieName']; } I find it useful to see the JSON in a more structured way. Tools like JSONLint, or browser addons like JSONView will reformat plain JSON into a more pretty layout. JSONView Similarly, in PHP it is often nice to see the structure of an array. For that, make sure you output plain text (e.g. header('Content-Type: text/plain')) rather than HTML, which will eat up your pretty whitespace unless you use something like a <pre> tag. var_export()
  8. The key part that you are missing is likely the use of SimpleXMLElement::children() to access elements under different namespaces. You have two namespaces to deal with; one for SOAP, and one for Mercury. The general idea is that children() selects children (weird, huh!) and you can specify the XML namespace that those children should belong to by prefix or URI. $envelope = simplexml_load_string('…'); $payment_id = (string) $envelope->children('soap', true) ->Body ->children('http://www.mercurypay.com/') ->InitializePaymentResponse ->InitializePaymentResult ->PaymentID; echo $payment_id; This will print out 8f19cc14-27fc-40ec-a929-bee4f043387f with your XML. Navigating through the XML structure like that can be long-winded: it is often a little neater to use XPath to get an array of the elements you're interested in. $envelope = simplexml_load_string('…'); $envelope->registerXPathNamespace('mercury', 'http://www.mercurypay.com/'); // xpath() returns an array, even if only one element matches $payment_ids = $envelope->xpath('descendant::mercury:PaymentID'); $payment_id = (string) $payment_ids[0]; echo $payment_id; Or, you could use a regular expression match. Helpful links SimpleXML Basic Usage XPath overview XML namespaces SimpleXMLElement::children() SimpleXMLElement::xpath()
  9. You're 'scuzed. P.S. The DateInterval and DatePeriod classes are super-duper useful, everyone should use them!
  10. The use of "new" there made me chortle.
  11. Tony's answer doesn't limit the value to being only one letter. Is that what you want?
  12. A good introduction is also Schlitt's XPath overview. Then there is always the XPath 1.0 specification, which is really handy for quickly finding exactly what you need.
  13. It's not silly at all. Having this sorts of questions on the intertubes is invaluable to others suffering from similar mistakes.
  14. If the value exists in a variable, it will be available in "clear text" in memory. You'll need to use that part of memory again. How you do that is far beyond the realm of a PHP support forum. Overwriting the variable, over even unset()-ing it, will not help. I don't know what you mean by "some kind of PHP "flush" command". Summary Yes, the value is visible in plain text. Personally, I wouldn't worry about it: if an attacker can run something to read your PHP script's memory, they've already got privileged access to the machine.
  15. And foreach is an array's best friend.
  16. Who?
  17. Did you even read the replies? The "var" is not being kept for PHP 4 compatibility, any version of CodeIgniter 2.0.0 or above requires PHP 5.
  18. I have a couple of comments, though they're not particularly anything to do with PDO at all. That side of things looks okay in your code. FormatPassword() This is a crazy way to hash a password, and going the extra mile to call sha1()/md5() six times is not doing you any favours. Instead, look towards using a different hashing implementation. For example, using the crypt() function with Blowfish and a suitable number of "rounds" would be an infinitely better choice. It's probably beyond the scope of a quick reply to delve into why this is so, some quick searching on the subject will bring up a wealth of information if you're interested. Also, if you're brave enough to be trying out the PHP 5.5.0 alphas then you could play with the password_hash() function which looks to introduce a new best-practice function for dealing with passwords in PHP. Since you're probably not able to use PHP 5.5.0 yet then here's what a call to crypt() might look like. $salt = ...; // Should be 22 characters of "./0-9A-Za-z" for Blowfish $hash = crypt($pass, '$2y$08$'.$salt); Special Note: Please carefully read the notes about the $2a$, $2x$, and $2y$ salt prefixes, in particular which versions of PHP have them. Also, be sure to set the number of rounds (08) to something sensible for your needs. A lower number makes the hashing consume less time, which is good for anyone trying to attack your system. A higher number makes hashing consume more time, which if you go crazy can cause creating a hash to take a very, very long time. Have a play around with the rounds, to see what works best for you. Salting Your code has a single salt for all passwords. This is also not a very good idea. It is much better practice to have a different salt for each password. This can be stored in the database too, to be looked up when checking the password later. For why this is a good idea, have a read up on salts and their effect on using "rainbow tables".
  19. balkan7, are you able to install PECL extensions? I only ask because as part of the Intl extension (and to be bundled with PHP 5.5) are some classes to make tasks like breaking up text into sentences super-easy. If you can, putting them to use would mean installing Intl 3 (currently 3.0.0b1) via pecl install intl-beta Then, playtime! <?php $text = 'Quis nostrud 05.10.2011 exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat. Aenean vel arcu at libero vestibulum bibendum. Integer sit amet lacus nibh, viverra feugiat ante. Ut justo libero, venenatis at tincidunt eget, dapibus vitae velit. Aliquam tempor, urna sed bibendum pharetra, metus diam vestibulum augue, sed adipiscing tortor ante vitae lacus. Donec congue egestas ipsum, sit amet porta lectus pellentesque at. '; $sentence_iterator = IntlBreakIterator::createSentenceInstance('en'); $sentence_iterator->setText($text); $sentences = iterator_to_array($sentence_iterator->getPartsIterator()); var_export($sentences); ?> This shows that $sentences is an array: array ( 0 => 'Quis nostrud 05.10.2011 exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ', 1 => 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat. ', 2 => 'Aenean vel arcu at libero vestibulum bibendum. ', 3 => 'Integer sit amet lacus nibh, viverra feugiat ante. ', 4 => 'Ut justo libero, venenatis at tincidunt eget, dapibus vitae velit. ', 5 => 'Aliquam tempor, urna sed bibendum pharetra, metus diam vestibulum augue, sed adipiscing tortor ante vitae lacus. ', 6 => 'Donec congue egestas ipsum, sit amet porta lectus pellentesque at. ', )
  20. Simply because no-one got around to updating those particular properties yet. There is nothing more to read into it than that.
  21. You could take a slightly different approach, like getting the list of tags and looking to see if any have an "infographic" tag. foreach ($xml->posts->post as $post) { $tags = array_map('strval', $post->xpath('tag')); if (in_array('infographic', $tags)) { // yay, has an infographic tag } else { // aww, not infographic } }
  22. The [ic] CSS could do with a little tweaking. It's especially ugly at the moment when used often throughout a post.
  23. This is trying to find all <users> elements that are descendants of the $masterElement. The $masterElement is representing the single <users> element that wraps the whole document: it has no descendant <users> elements, only <user>, <name>, and <score> elements. It looks like you wanted to use $masterElement->getElementsByTagName('user'). Then you used ->item(3). Your XML document has three <user> elements so, assuming you change the call to getElementsByTagname() as shown above, you could access those via item(0), item(1), and item(2) respectively. There is no fourth <user> element to get using item(3). It looks like you wanted to use ->item(2). So given those changes to that one line of code, the code posted in post #5 above would work (it would delete the cobus user) and would not present an error. Could you give it a try and let us know how you get on?
  24. Try again. Congratulations.
×
×
  • 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.