How to reindex an array?
Use array_values: $reindexed_array = array_values($old_array);
Use array_values: $reindexed_array = array_values($old_array);
No need for extra blocks and named locations and everything. Also move the index line outside the location block server { index index.html index.php; location / { try_files $uri $uri/ $uri.html $uri.php$is_args$query_string; } location ~ \.php$ { try_files $uri =404; # add fastcgi_pass line here, depending if you use socket or port } } Keep … Read more
The PHP and the HTML should each be indented so that they are correct with respect to themselves in source form, irrespective of each other and of outputted form: <table> <?php foreach ($rows as $row): ?> <tr> <?php if ($row->foo()): ?> <?php echo $row ?> <?php else: ?> Something else <?php endif ?> </tr> <?php … Read more
function urlExists($url=NULL) { if($url == NULL) return false; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300){ return true; } else { return false; } } This was grabbed from this post on how to check if a URL exists. Because … Read more
Chunking files is the fastest / simplest method in PHP, if you can’t or don’t want to make use of something a bit more professional like cURL, mod-xsendfile on Apache or some dedicated script. $filename = $filePath.$filename; $chunksize = 5 * (1024 * 1024); //5 MB (= 5 242 880 bytes) per one chunk of … Read more
I now found solution by using mysqli instead of mysql. <?php // enable error reporting mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //connect to database $connection = mysqli_connect(“hostname”, “user”, “password”, “db”, “port”); //run the store proc $result = mysqli_query($connection, “CALL StoreProcName”); //loop the result set while ($row = mysqli_fetch_array($result)){ echo $row[0] . ” – ” . + $row[1]; } … Read more
You are looking for the break statement. $arr = array(‘one’, ‘two’, ‘three’, ‘four’, ‘stop’, ‘five’); while (list(, $val) = each($arr)) { if ($val == ‘stop’) { break; /* You could also write ‘break 1;’ here. */ } echo “$val<br />\n”; }
Just doing a lot of stuff that you don’t really understand, is not going to help you. You need to understand what injection attacks are and exactly how and where you should do what. In bullet points: Disable magic quotes. They are an inadequate solution, and they confuse matters. Never embed strings directly in SQL. … Read more
Take a look at mime_content_type or Fileinfo. These are built-in PHP commands for determining the type of a file by looking at the contents of the file. Also check the comments on the above two pages, there are some other good suggestions. Personally I’ve had good luck using something that’s essentially system(“file -bi $uploadedfile”), but … Read more
Turns out there was two issues here: 1. $_ENV is only populated if php.ini allows it, which it doesn’t seem to do by default, at least not in the default WAMP server installation. ; This directive determines which super global arrays are registered when PHP ; starts up. If the register_globals directive is enabled, it … Read more