Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. The time of the post is recorded in the database. The date calculation uses this field to display how long ago the post was created. Easy. You would use a database query to obtain the most recent posts if you liked using the date field.
  2. eh? Doesn't limit anything. It is an example!
  3. Was just a quick example if(preg_match('%{sls}(.*){/sle}%s', $subject, $regs)) { How do you suggest rewriting to match absolutely anything inside the capture group?
  4. Why would you ever need to do this with a primary key?
  5. Like I said this is inefficient! You should construct an array as below using just a single query. If there are 10 categories then your code is running 10 queries plus the main query (11 queries). Array ( [0] => Array ( [maincat] => category 1 [subcats] => Array ( [0] => sub cat 1 [1] => sub cat 2 [2] => sub cat 3 ) ) [1] => Array ( [maincat] => category 2 [subcats] => Array ( [0] => sub cat 1 [1] => sub cat 2 [2] => sub cat 3 ) ) [2] => Array ( [maincat] => category 3 [subcats] => Array ( [0] => sub cat 1 ) ) )
  6. Of course. You should just use 1 query to get all categories / subcategories using a join. Then create a multidimensional array to place all subcats under the parent category, then loop over that array to create the output. Using a query nested in a loop is not efficient.
  7. Learn php CURL to fetch remote data
  8. Have you restarted the server?
  9. example: // start script as background process exec("php /path/to/file.php > /dev/null &");
  10. Get CSS help and then loop over the specific area. Post in CSS forum
  11. Execute a background process as ToonMariner has stated. You would never wait for that to complete in a web browser!
  12. Yes, only you do not enclose variables in single quotes as function parameters '$value' should be just $value
  13. That would be preg_replace()
  14. Thats because it contains line break characters. Ammend the regex to if(preg_match('%{sls}(.*){/sle}%s', $subject, $regs)) {
  15. Get a copy of regex buddy to help you with regex http://www.regexbuddy.com/
  16. I cant tell if that is a pipe or an l between ss and se. If not <?php $subject = "{sls}Content to return here{/sle}"; if(preg_match('%{sls}(.*){/sle}%', $subject, $regs)) { print $regs[0]; } ?> If it is a pipe <?php $subject = "{s|s}Content to return here{/s|e}"; if(preg_match('%{s\\|s}(.*){/s\\|e}%', $subject, $regs)) { print $regs[0]; } ?>
  17. It is a poor function to use for validation as a variable can be set with anything. Think of url params. You could exectute code by adding them to the url i.e. if(isset($_GET['name'])) { } I could execute the code using http://www.xyz.com?name=123 You should really check the data type or if the variable contains a certain string i.e. $names = array('neil', 'john', 'paul'); if(strlen($_GET['name']) && in_array($_GET['name'], $names)) { // name is valid }
  18. No problem. I have added comments to make clear. If you want to make it more advanced then things like usernames/passwords should be a certain length and contain no spaces. Rather than checking if the fields are just empty you may want to check that the correct number of characters and type are present. <?php session_start(); // form has been submitted if($_POST['buttonLogin'] == 'Login') { // create array. hold any errors in the $errors array $errors = array(); // create an array of the form field names that should not be empty $fields = array('UserId' => 'username', 'Password' => 'password'); // loop through each field foreach($fields as $key => $name) { // if the field is empty then store its name in the errors array if(!strlen(trim($_POST[$key]))) { $errors[] = $name; } } // check for errors by counting the number of elements in the array if(count($errors)) { // display the name of each empty field print "The following fields must be complete: ".implode(", ", $errors); } else { // there are no errors } } ?>
  19. isset() is such a poor function to use!
  20. Firstly you need to check that the form has been submitted before checking the fields <?php session_start(); // form has been submitted if($_POST['buttonLogin'] == 'Login') { $errors = array(); $fields = array('UserId' => 'username', 'Password' => 'password'); foreach($fields as $key => $name) { if(!strlen(trim($_POST[$key]))) { $errors[] = $name; } } // check for errors if(count($errors)) { print "The following fields must be complete: ".implode(", ", $errors); } else { } } ?>
  21. You need all programs available on your server that can perform the tasks i.e WHOIS from the CLI, PHP itself has some functions to utilize such as DNS record lookups, look into these. If you use PHP to create the website then you need the ability to execute the server apps through PHP and parse the results to display to the user. i.e. // whois lookup exec("whois xyz.com", $output);
×
×
  • 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.