256 Kilobytes

Server-Side Answers

Type AnswersAsk and answer questions, if that is something that you want to do. Category Server-SideDiscuss server-side development, such as PHP. Tag All

Profile Photo - Some Guy

How to write "correct horse battery staple" passwords in PHP?

Answers in Server-Side | By Some Guy

Published 5 days agoTue, 19 Mar 2019 19:19:24 -0700

Profile Photo - August R. Garcia

Last Reply function correct_horse_battery_staple() { // The file that contains the words you want to use $f_contents = file(public_path() .... August R. Garcia,

Tue, 19 Mar 2019 19:23:10 -0700 5 days ago
🗨
1
🐏
0
👁
31
Profile Photo - Some Guy

[Dreamhost] Increase PHP memory limit?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:30:36 -0800

Profile Photo - August R. Garcia

Last Reply Also, if you're running out of memory, note that for shared hosting and VPS setups, MySQL runs on a separate machine/partition from your website's fil... August R. Garcia,

Also, if you're running o...

Sat, 23 Feb 2019 01:54:09 -0800 1 month ago
🗨
2
🐏
0
👁
77
Profile Photo - Some Guy
Profile Photo - August R. Garcia

Last Reply Something like this should work: function greentext(DOMDocument $xml_doc) { // Get all P tags $nodes = $xml_doc->getElementsBy... August R. Garcia,

Something like this shoul...

Wed, 06 Feb 2019 19:51:25 -0800 1 month ago
🗨
1
🐏
0
👁
176
Profile Photo - Some Guy
Profile Photo - Some Guy

Here's the code:

MoreHere's the code: // $recent is an array of associative arrays
🗨
0
🐏
0
👁
44
Profile Photo - Some Guy

[PHP] Add ids to domdocument?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:35:36 -0800

Profile Photo - August R. Garcia

Last Reply There is also some code in this article that does this: https://www.256kilobytes.com/content/show/3104/php-how-to-configure-a-website-to-show-jump-... August R. Garcia,

There is also some code i...

Sat, 02 Feb 2019 22:32:32 -0800 1 month ago
🗨
2
🐏
0
👁
58
Profile Photo - Some Guy

[PHP] Sort associative array by value?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:32:36 -0800

Profile Photo - August R. Garcia

Last Reply PHP documentation for arsort(): http://php.net/manual/en/function.arsort.php Also, there are a few other array sorting options: sort() -... August R. Garcia,

PHP documentation for ars...

Sat, 02 Feb 2019 22:07:44 -0800 1 month ago
🗨
2
🐏
0
👁
55
Profile Photo - Some Guy

How to delete a database in PHPmyadmin?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:32:06 -0800

Profile Photo - August R. Garcia

Last Reply You can also directly run these commands through the PHPMyAdmin UI: SHOW DATABASES; If you need to look up the database name(s) DROP... August R. Garcia,

You can also directly run...

Sat, 02 Feb 2019 21:43:54 -0800 1 month ago
🗨
2
🐏
0
👁
60
Profile Photo - Some Guy
Profile Photo - roxblade

Last Reply First of all, make sure you restart Apache (server) after you have modified the php.ini. Also, ensure that the file that's causing this error to pop u... roxblade,

First of all, make sure y...

Sat, 02 Feb 2019 07:07:27 -0800 1 month ago
🗨
1
🐏
0
👁
60
Profile Photo - Some Guy

[PHP] sort multidimensional array by value?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:33:56 -0800

Profile Photo - roxblade

Last Reply Before PHP 5.2, you will need to define a custom sorting function to do that. Let's say it goes like this: function sortByOrder($a, $b) { re... roxblade,

Before PHP 5.2, you will...

Fri, 01 Feb 2019 03:00:53 -0800 1 month ago
🗨
1
🐏
0
👁
67
Profile Photo - Some Guy
Profile Photo - roxblade

Last Reply This is most probably happening because DNS lookup is failing. If you're particularly sure that the server is accessible and you can open it otherwise... roxblade,

This is most probably hap...

Fri, 01 Feb 2019 02:57:17 -0800 1 month ago
🗨
1
🐏
0
👁
55
Profile Photo - Some Guy

[PHP] Specify timezone in a date object?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:34:56 -0800

Profile Photo - roxblade

Last Reply Use the setTimezone function for this. This works from PHP 5 up until the latest version. DateTime::setTimezone -- date_timezone_set This w... roxblade,

Use the setTimezone funct...

Fri, 01 Feb 2019 02:52:46 -0800 1 month ago
🗨
1
🐏
0
👁
48
Profile Photo - Some Guy

How to remove/rewrite all "index.php" strings in a URL using .htaccess?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:35:16 -0800

Profile Photo - roxblade

Last Reply It's simple. Add the following code to your .htaccess file and all .index.php will be removed from your URLs. <IfModule mod_rewrite.c>... roxblade,

It's simple. Add the foll...

Fri, 01 Feb 2019 02:50:49 -0800 1 month ago
🗨
1
🐏
0
👁
52
Profile Photo - Some Guy

How to escape user input for an HTML input's "value" attribute?

Answers in Server-Side | By Some Guy

Published 3 months agoSun, 02 Dec 2018 03:42:29 -0800

Profile Photo - August R. Garcia

Last Reply Note that if you're talking about an attribute, by default htmlspecialchars() does not encode the single quote ( ' ) chara... August R. Garcia,

Note that if you're t...

Sun, 20 Jan 2019 18:33:20 -0800 2 months ago
🗨
2
🐏
0
👁
67
Profile Photo - Some Guy

[PHP] What is an associative array?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:31:36 -0800

Profile Photo - Hash Brown

Last Reply In PHP there are two types of array, indexed and associative. Which one is best for you depends on what you're doing. Indexed Arrays Thes... Hash Brown,

In PHP there are two type...

Sun, 20 Jan 2019 18:18:18 -0800 2 months ago
🗨
1
🐏
0
👁
58
Profile Photo - Some Guy

[PHP] Is it possible to get the next item's value in a PHP foreach loop?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:31:46 -0800

Profile Photo - Hash Brown

Last Reply Hello, If your array keys are continuous, it's very simple to do. foreach ($arr as $key => $val) { if (isset($arr[$key+1])) {... Hash Brown,

Hello,

Sat, 19 Jan 2019 07:06:31 -0800 2 months ago
🗨
1
🐏
0
👁
68
Profile Photo - Some Guy

[PHP] Swap two variables without using third?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:32:46 -0800

Profile Photo - Hash Brown

Last Reply Hello, There is no function that will do this but it's pretty easily done using lists and arrays list($a,$b) = array($b,$a); Learn mo... Hash Brown,

Hello,

Mon, 14 Jan 2019 16:56:14 -0800 2 months ago
🗨
1
🐏
0
👁
64
Profile Photo - Some Guy

[PHP] Get longest word in string?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:31:56 -0800

Profile Photo - Hash Brown

Last Reply This is fairly simple homie. A basic solution of this would be to explode the string on spaces to turn the string into an array of words. We can... Hash Brown,

This is fairly simple hom...

Mon, 14 Jan 2019 16:47:58 -0800 2 months ago
🗨
1
🐏
0
👁
74
Profile Photo - Some Guy

[PHP] Convert a decimal to a percent?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:31:26 -0800

Profile Photo - Hash Brown

Last Reply This is more a maths thing than anything else. If you have the decimal (0 to 1) and want to turn it into a percentage you simply multiply by 100.... Hash Brown,

This is more a maths thin...

Mon, 14 Jan 2019 16:39:07 -0800 2 months ago
🗨
1
🐏
0
👁
47
Profile Photo - Some Guy

Function comparable to PHP implode() in Google Sheets?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:30:16 -0800

Profile Photo - Hash Brown

Last Reply #fuckTurks Hash Brown,

#fuckTurks

Mon, 14 Jan 2019 16:23:51 -0800 2 months ago
🗨
3
🐏
0
👁
70
Profile Photo - Some Guy
Profile Photo - Hash Brown

Last Reply And just to follow on PHP is pretty retarded. Making your code work with the least number of changes you have to make to php.ini the better. Hash Brown,

And just to follow on<br...

Mon, 14 Jan 2019 16:23:17 -0800 2 months ago
🗨
2
🐏
0
👁
54
Profile Photo - Some Guy

How to fix "Currently unable to handle this request HTTP error 500"?

Answers in Server-Side | By Some Guy

Published 3 months agoSun, 16 Dec 2018 09:39:12 -0800

Profile Photo - Hash Brown

Last Reply HTTP 500 errors are nortorious for being a bitch to fix. The code signals a server error where it couldn't be more specific in what went wron... Hash Brown,

HTTP 500 errors are norto...

Mon, 14 Jan 2019 16:10:07 -0800 2 months ago
🗨
1
🐏
0
👁
53
Profile Photo - Some Guy

How to choose a random array element in PHP?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:31:16 -0800

Profile Photo - Hash Brown

Last Reply You can use the array_rand() function $cars =array("BMW", "Opel", "Mazda", "Triumph", "Vauxhall", "Ford"); $random_keys = array_rand($cars, 3);... Hash Brown,

You can use the array_ran...

Mon, 14 Jan 2019 15:56:18 -0800 2 months ago
🗨
1
🐏
0
👁
38
Profile Photo - Some Guy

Does PHP need a closing tag?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:33:16 -0800

Profile Photo - Hash Brown

Last Reply Code should still run, it's a scripting language after all. But this doesn't mean you shouldn't use closing tags. This becomes most imp... Hash Brown,

Code should still run, it...

Mon, 14 Jan 2019 15:51:29 -0800 2 months ago
🗨
1
🐏
0
👁
42
Profile Photo - Some Guy

What is this file? Path: modules/core/templates/default/loginuserpass.php

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:34:06 -0800

Profile Photo - Hash Brown

Last Reply It's a file that belongs to SimpleSamlPHP Hash Brown,

It's a file that belo...

Mon, 14 Jan 2019 15:39:41 -0800 2 months ago
🗨
1
🐏
0
👁
45
Profile Photo - Some Guy

[PHP] How to get a random float between 0 and 1?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:34:46 -0800

Profile Photo - Hash Brown

Last Reply Theres no standard PHP function for random floats specifically, but you can get a random whole number and then divide it to create a float. $rand... Hash Brown,

Theres no standard PHP fu...

Mon, 14 Jan 2019 15:02:05 -0800 2 months ago
🗨
1
🐏
0
👁
40
Profile Photo - Some Guy

[PHP] Issue with file_put_contents not working?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:33:36 -0800

Profile Photo - Hash Brown

Last Reply Lots of the "file_" functions are disabled as standard in PHP so the first step is checking your php.ini file and enabling it. The next m... Hash Brown,

Lots of the "file_&q...

Mon, 14 Jan 2019 14:57:22 -0800 2 months ago
🗨
1
🐏
0
👁
42
Profile Photo - Some Guy

[PHP] Check if positive integer?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:35:26 -0800

Profile Photo - Hash Brown

Last Reply Yes this is very easy Just check that the integer is bigger than 0 For example: $i = 15; if(is_numeric($i) && $i >= 0){ echo... Hash Brown,

Yes this is very easy<br...

Mon, 14 Jan 2019 14:43:42 -0800 2 months ago
🗨
1
🐏
0
👁
33
Profile Photo - Some Guy

How to check if a string is valid XML using PHP?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:34:26 -0800

Profile Photo - Hash Brown

Last Reply You can use PHP's DomDocument::validate feature dear for all your XML validation needs $dom = new DOMDocument; $dom->Load('book.xml'); //... Hash Brown,

You can use PHP's Dom...

Mon, 14 Jan 2019 14:28:34 -0800 2 months ago
🗨
1
🐏
0
👁
32
Profile Photo - Some Guy

[PHP] How to remove duplicate dashes?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:34:36 -0800

Profile Photo - Hash Brown

Last Reply preg_replace() will do this pretty easily. I'm not sure if you want to completely remove double dashes or replace them with a single dash, the... Hash Brown,

preg_replace() will do th...

Mon, 14 Jan 2019 14:23:10 -0800 2 months ago
🗨
1
🐏
0
👁
27
Profile Photo - Some Guy

[PHP] Remove empty array elements?

Answers in Server-Side | By Some Guy

Published 2 months agoSun, 13 Jan 2019 04:35:46 -0800

Profile Photo - Hash Brown

Last Reply Hey, If you are dealing with an array of strings you might want to look at array filters, this would work like so: array_filter($yourArray, fu... Hash Brown,

Hey,

Mon, 14 Jan 2019 14:08:57 -0800 2 months ago
🗨
1
🐏
0
👁
33