Jump to content


Staff Alumni
  • Posts

  • Joined

  • Last visited

  • Days Won


salathe last won the day on March 7 2019

salathe had the most liked content!

About salathe

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Edinburgh, Scotland

Recent Profile Visitors

4,327 profile views

salathe's Achievements


Member (2/5)



  1. This is for PHPMailer 6. This is for PHPMailer 5. Which version do you actually have?
  2. It looks like you're scraping pages from the PHP manual, so taking one of those as an example, the HTML looks like this (super-stripped down for simplicity): <?php $html = '<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <!-- lots more goes here --> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); var_dump($dom->childNodes->length); foreach ($dom->childNodes as $childNode) { var_dump(get_class($childNode)); } The above outputs the following: int(2) string(15) "DOMDocumentType" string(10) "DOMElement" This shows that the document ($dom) has two child nodes: 1. the document type (<!DOCTYPE html>) and 2. the "html" element. Hope that helps. ?
  3. From the docs: This means that the expression you want to be matched is a single, text (string) value. If you're using a prepared statement, in PHP, with PDO, that means a single question mark (?) or a single ":name" placeholder if you're going for named parameters. A quick demo example: <?php $db = new PDO("sqlite::memory:"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->exec("CREATE VIRTUAL TABLE example USING FTS5 (a, b)"); $db->exec("INSERT INTO example (a, b) VALUES ('this is an amazing message', 'kittens are lovely')"); $db->exec("INSERT INTO example (a, b) VALUES ('this is a great message', 'dogs are also lovely')"); $db->exec("INSERT INTO example (a, b) VALUES ('this is a message', 'hamsters are best')"); $query = $db->prepare('SELECT * FROM example WHERE example MATCH ?'); $query->execute(array('(b: kittens) OR (a: great)')); $rows = $query->fetchAll(); print_r($rows); The above example outputs the two matching rows. Array ( [0] => Array ( [a] => this is an amazing message [b] => kittens are lovely ) [1] => Array ( [a] => this is a great message [b] => dogs are also lovely ) ) Hope that helps.
  4. A (very) brief note about Countable objects Classes implementing the Countable interface define and implement their own count() method. The DOMNodeList class is one such class. Instances of classes that implement the Countable interface can be passed to the count() function, and their own special count() method gets called. In DOMNodeList's case, that method returns the number of nodes in the list. There is nothing stopping you from calling the count() method on the object (e.g. $myobject->count()) rather than the count() function (e.g. count($myobject)), if that's what you want to do. How the heck am i supposed to count the childNodes? Back to your original question. There are several ways to get the number of nodes in a DOMNodeList (which is what your $dom->childNodes is). 1. $dom->childNodes->length 2. count($dom->childNodes) 3. $dom->childNodes->count()
  5. Inside your last_activity.php file, you close the connection to the database with mysqli_close($dbc). This means that for anything below where you include that file, the database connection is not available. Moving that require_once() to the end "fixes" things because if it's the last thing using the database then it's okay to close the connection. The simplest thing to do is delete that line of code which closes the connection.
  6. Now you do! The only necessary change, to do what you described, would be: From this // Execute query. mysqli_stmt_execute($stmt); // Verify Update. if (mysqli_stmt_affected_rows($stmt)!==1){ To this // Execute query. $success = mysqli_stmt_execute($stmt); // Verify Update. if ($success === FALSE) { Don't beat yourself up over not realising that zero affected rows isn't an error. Learning material, particularly on the internets, often stresses the supposed importance of checking for the number of affected rows for INSERT/UPDATE/DELETE queries, as an indicator of success/failure. So much so, that it is easy to miss the fact that sometimes when there really is nothing to update, depending on what the script is trying to do, it's okay to not have any rows affected.
  7. Yep I follow you. The trouble looks to be that you consider zero updated rows as an error when that's not the case. If the logged_in is already 1, and you update it to 1, then MySQL will report zero rows updated --- but that's fine. You don't want to give an error message when no rows are updated. It looks to me like you should really be checking on the return value of mysqli_stmt_execute(), to see if something went wrong with the query; not counting how many rows changed.
  8. The logic in the code in the OP makes no sense at all. It reads... If the user is logged in, update the database to show that they are logged in. Whaaa? If they're already logged in (as shown by $_SESSION['loggedIn'] being true), and you update the database then of course you'll get zero rows updated because the database will be trying to update the logged_in column from 1 to 1 again.
  9. Your regex starts like /[^OWNER NAME] This is not doing what you think it is! It's actually just checking for "a single character that is not in the set of characters O, W, N, E, R, <space>, A and M". You probably want something like /^(?!OWNER NAME) which makes sure that the line doesn't start with "OWNER NAME". For help on the (?!...) search on "regex lookaround".
  10. Not entirely true. When join() was introduced in PHP 3.0b5 (a very long time ago) it was immediately an "alias" for implode(), which means that it does exactly (literally!) the same thing. However, split() and explode() are different functions entirely. split() uses a POSIX regular expression to break a string into pieces (sometimes the regular expression is a string of literal characters). explode() does not use regular expressions, it just splits of the characters given. So, there is some overlap in what split() and explode() can do but they're not the same at all. split() was deprecated as part of the wider deprecation of all of the POSIX regex functions in PHP 5.3.0. None of the other three functions (explode(), join(), implode()) are deprecated.
  11. It looks like you're not really grasping the concept of OOP clearly at all, instead you're essentially wrapping a bunch of procedural behaviour (discrete functions) within a class. Those different parts that you mention should belong in very different, separate classes; just to give a couple of examples, logging in is all about authentication whereas restriction is about authorization -- two separate entities right there! Getting/sending PMs is entirely unrelated to retrieving a user's age, so should definitely not belong in the same class. Etc..
  12. It sounds like you're wanting to do too much with a single class. Can you give a concrete example of a class that you have which you think would benefit from being spread across multiple files, and explain why you think so?
  • 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.