256 Kilobytes

All Content > PHP

Type All Category All Tag PHPPHP: Hypertext Preprocessor is a scripting language used heavily in server-side development. PHP is frequently used for templating.

Profile Photo - August R. Garcia
Profile Photo - August R. Garcia

Holy shit, use krsort(), not arsort().

MoreOkay, you fucking cocksuckers, I'm going to stab myself for the reason stated in the description.Anyway, here's some code to make a fucking "recently...
🗨 0
🐏 0
👁 2,124
Profile Photo - Some Guy

[PHP] Add ids to domdocument?

Answers in Server-Side | By Some Guy

Published

Profile Photo - August R. Garcia

Last ReplyThere 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 -08002 years ago1
🗨 2
🐏 0
👁 451
Profile Photo - Some Guy

[PHP] Sort associative array by value?

Answers in Server-Side | By Some Guy

Published

Profile Photo - August R. Garcia

Last ReplyPHP 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 -08002 years ago1
🗨 2
🐏 0
👁 550
Profile Photo - Some Guy
Profile Photo - roxblade

Last ReplyFirst 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 -08002 years ago1
🗨 1
🐏 0
👁 806
Profile Photo - Some Guy
Profile Photo - roxblade

Last ReplyIt is very tricky, to be honest. The first thing you should do is check if creating a larger image solves your problem. It's the simplest way, real... roxblade,

It is very tricky, to be...

Fri, 01 Feb 2019 03:13:48 -08002 years ago1
🗨 1
🐏 0
👁 560
Profile Photo - Some Guy

[PHP] sort multidimensional array by value?

Answers in Server-Side | By Some Guy

Published

Profile Photo - roxblade

Last ReplyBefore 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 -08002 years ago1
🗨 1
🐏 0
👁 550
Profile Photo - Some Guy
Profile Photo - roxblade

Last ReplyThis 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 -08002 years ago1
🗨 1
🐏 0
👁 466
Profile Photo - Some Guy

[PHP] Specify timezone in a date object?

Answers in Server-Side | By Some Guy

Published

Profile Photo - roxblade

Last ReplyUse 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 -08002 years ago1
🗨 1
🐏 0
👁 432
Profile Photo - Some Guy

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

Answers in Server-Side | By Some Guy

Published

Profile Photo - August R. Garcia

Last ReplyNote 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 -08002 years ago1
🗨 2
🐏 0
👁 488
Profile Photo - Some Guy

Solve "trying to get property of non-object"?

Answers in Databases | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyYou're probably trying to get the value from an array with object syntax. Most database data is handled in arrays, not objects. If you are d... Hash Brown,

You're probably tryin...

Sun, 20 Jan 2019 18:29:51 -08002 years ago1
🗨 1
🐏 0
👁 480
Profile Photo - Some Guy

[PHP] What is an associative array?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyIn 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 -08002 years ago1
🗨 1
🐏 0
👁 419
Profile Photo - Some Guy

Solve "sqlstate[hy000] [2002] connection refused"?

Answers in Databases | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyThese errors are kind of generic and don't point to anything specific. In general you want to start off: Make sure you're using the c... Hash Brown,

These errors are kind of...

Sun, 20 Jan 2019 18:05:00 -08002 years ago1
🗨 1
🐏 0
👁 532
Profile Photo - Some Guy
Profile Photo - Hash Brown

Last ReplyHello, 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 -08002 years ago1
🗨 1
🐏 0
👁 446
Profile Photo - Some Guy

[PHP] Swap two variables without using third?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyHello, 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 -08002 years ago1
🗨 1
🐏 0
👁 431
Profile Photo - Some Guy

[PHP] Get longest word in string?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyThis 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 -08002 years ago1
🗨 1
🐏 0
👁 722
Profile Photo - Some Guy

[PHP] Convert a decimal to a percent?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyThis 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 -08002 years ago1
🗨 1
🐏 0
👁 367
Profile Photo - Some Guy

Function comparable to PHP implode() in Google Sheets?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last Reply#fuckTurks Hash Brown,

#fuckTurks

Mon, 14 Jan 2019 16:23:51 -08002 years ago1
🗨 3
🐏 0
👁 448
Profile Photo - Some Guy
Profile Photo - Hash Brown

Last ReplyAnd 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

Mon, 14 Jan 2019 16:23:17 -08002 years ago1
🗨 2
🐏 0
👁 342
Profile Photo - Some Guy
Profile Photo - Hash Brown

Last ReplyHTTP 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 -08002 years ago1
🗨 1
🐏 0
👁 400
Profile Photo - Some Guy

How to choose a random array element in PHP?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyYou 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 -08002 years ago1
🗨 1
🐏 0
👁 329
Profile Photo - Some Guy

Does PHP need a closing tag?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyCode 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 -08002 years ago1
🗨 1
🐏 0
👁 345
Profile Photo - Some Guy
Profile Photo - Hash Brown

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

It's a file that belo...

Mon, 14 Jan 2019 15:39:41 -08002 years ago1
🗨 1
🐏 0
👁 328
Profile Photo - Some Guy

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

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyTheres 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 -08002 years ago1
🗨 1
🐏 0
👁 314
Profile Photo - Some Guy

[PHP] Issue with file_put_contents not working?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyLots 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 -08002 years ago1
🗨 1
🐏 0
👁 448
Profile Photo - Some Guy

[PHP] Check if positive integer?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyYes 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

Mon, 14 Jan 2019 14:43:42 -08002 years ago1
🗨 1
🐏 0
👁 277
Profile Photo - Some Guy

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

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyYou 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 -08002 years ago1
🗨 1
🐏 0
👁 301
Profile Photo - Some Guy

[PHP] How to remove duplicate dashes?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last Replypreg_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 -08002 years ago1
🗨 1
🐏 0
👁 264
Profile Photo - Some Guy

[PHP] Remove empty array elements?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Hash Brown

Last ReplyHey, 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 -08002 years ago1
🗨 1
🐏 0
👁 327
Profile Photo - Some Guy

Fixing "MySQLi_real_connect(): (hy000/2002): no such file or directory?"

Answers in Databases | By Some Guy

Published | Last Update

Profile Photo - Hash Brown

Last ReplyGo into your script or config file and find your database credentials. Look for "localhost" and replace it with "127.0.0.1".... Hash Brown,

Go into your script or co...

Mon, 14 Jan 2019 14:00:03 -08002 years ago1
🗨 1
🐏 0
👁 4,128
Profile Photo - Some Guy
Profile Photo - Hash Brown

Last ReplyHello, This is fairly simple, adding the code below to your .htaccess file will blanket remove all .php extentions from your URL. #remove php... Hash Brown,

Hello,

Mon, 14 Jan 2019 13:18:34 -08002 years ago1
🗨 1
🐏 0
👁 295