-
Posts
3,584 -
Joined
-
Last visited
-
Days Won
3
Everything posted by JonnoTheDev
-
[SOLVED] dynamic date tracker for blog posts
JonnoTheDev replied to Lambneck's topic in PHP Coding Help
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. -
eh? Doesn't limit anything. It is an example!
-
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?
-
Why would you ever need to do this with a primary key?
-
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 ) ) )
-
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.
-
Learn php CURL to fetch remote data
-
URL file-access is disabled in the server configuration
JonnoTheDev replied to ffc's topic in PHP Coding Help
Have you restarted the server? -
example: // start script as background process exec("php /path/to/file.php > /dev/null &");
-
Get CSS help and then loop over the specific area. Post in CSS forum
-
Execute a background process as ToonMariner has stated. You would never wait for that to complete in a web browser!
-
Yes, only you do not enclose variables in single quotes as function parameters '$value' should be just $value
-
That would be preg_replace()
-
Thats because it contains line break characters. Ammend the regex to if(preg_match('%{sls}(.*){/sle}%s', $subject, $regs)) {
-
Get a copy of regex buddy to help you with regex http://www.regexbuddy.com/
-
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]; } ?>
-
How to make website like domaintools.com ?
JonnoTheDev replied to ankur0101's topic in PHP Coding Help
yes -
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 }
-
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 } } ?>
-
isset() is such a poor function to use!
-
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 { } } ?>
-
How to make website like domaintools.com ?
JonnoTheDev replied to ankur0101's topic in PHP Coding Help
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);