256 Kilobytes

Server-Side Answers > PHP

Type AnswersAsk and answer questions, if that is something that you want to do. Category Server-SideDiscuss server-side development, such as PHP. 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

[Solved] Automatic Copyright Footer Dates in Laravel/Basically Vanilla PHP

Answers in Server-Side | By August R. Garcia

Published | Last Update

Profile Photo - August R. Garcia

The only part about this that isn't vani...

MoreThe only part about this that isn't vanilla PHP is using {{ $var }} as shorthand for <?= htmlspecialchars($var); ?>. <style> .footer...
🗨 0
🐏 0
👁 549
Profile Photo - August R. Garcia

[Solved] Favicon.ico Files not Caching on Chrome

Answers in Server-Side | By August R. Garcia

Published | Last Update

Profile Photo - August R. Garcia

Slash "solved."Truly a quality hack.

MoreAs discussed previously, there are a fair number of dumbass things that can be done with base64 encoding that are occasionally so dumb that they even...
🗨 0
🐏 1
👁 337
Profile Photo - August R. Garcia
Profile Photo - August R. Garcia

TL;DR: Use $GLOBALS

MoreThe Laravel caching functions seem to not have specific built-in functionality to cache a query for only the current pageload, but it can easily be do...
🗨 0
🐏 0
👁 453
Profile Photo - Some Guy

How do I solve "Cannot use object of type stdclass as array"?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Univa

Last ReplyWhen we use json_decode();, we get an object of type stdClass as return type.  1. Cast the object to array. This can be achieved as follows.... Univa,

When we use json_decode()...

Wed, 08 May 2019 08:38:04 -07002 years ago1
🗨 1
🐏 0
👁 565
Profile Photo - Some Guy

[PHP] Push to associative array?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Univa

Last ReplyIt will merge two arrays and combine their items in a single array. Example Code - $existing_array = array('a'=>'b', 'b'=>'c'); $new_arra... Univa,

It will merge two arrays...

Wed, 08 May 2019 08:16:57 -07002 years ago1
🗨 1
🐏 0
👁 488
Profile Photo - Some Guy
Profile Photo - Univa

Last ReplyLog in as root in phpMyAdmin Create a database called PHPMyAdmin Create a user called pma and set the "host" to the hostname or IP address... Univa,

Wed, 24 Apr 2019 08:13:19 -07002 years ago1
🗨 1
🐏 0
👁 583
Profile Photo - August R. Garcia
Profile Photo - Some Guy

Last ReplyAlso, this tool is fairly useful: https://incarnate.github.io/curl-to-php/ Some Guy,

Also, this tool is fairly...

Sun, 14 Apr 2019 03:35:46 -07002 years ago1
🗨 1
🐏 0
👁 556
Profile Photo - August R. Garcia
Profile Photo - August R. Garcia

For "Authorization: Bearer "

MoreThe PHP Function <?php // This function makes the equivalent of the cURL call below: // curl -v<200b> https://api.sandbox.paypal.com/v...
🗨 0
🐏 0
👁 487
Profile Photo - Some Guy
Profile Photo - August R. Garcia

Last ReplyThis line: unset( $recent($key) );  Should be: unset( $recent[$key] );  August R. Garcia,

This line:

Sun, 07 Apr 2019 12:10:37 -07002 years ago1
🗨 2
🐏 0
👁 536
Profile Photo - Some Guy

Fix "Port 80 in use by "unable to open process" with pid 4!"?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Univa

Last ReplySome of the program that may be using Port 80: Skype: Skype uses port 80/443 by default.  Go to tools >options > advanced >conn... Univa,

Some of the program that...

Thu, 28 Mar 2019 11:56:18 -07002 years ago1
🗨 1
🐏 0
👁 571
Profile Photo - Some Guy

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

Answers in Server-Side | By Some Guy

Published

Profile Photo - August R. Garcia

Last Replyfunction 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 -07002 years ago1
🗨 1
🐏 0
👁 519
Profile Photo - Some Guy

[Dreamhost] Increase PHP memory limit?

Answers in Server-Side | By Some Guy

Published

Profile Photo - August R. Garcia

Last ReplyAlso, 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 -08002 years ago1
🗨 2
🐏 0
👁 717
Profile Photo - Some Guy
Profile Photo - August R. Garcia

Last ReplySomething 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 -08002 years ago1
🗨 1
🐏 0
👁 928
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
👁 465
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
👁 565
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
👁 827
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
👁 573
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
👁 487
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
👁 454
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
👁 508
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
👁 451
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
👁 474
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
👁 450
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
👁 755
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
👁 386
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
👁 465
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
👁 361
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
👁 420
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
👁 355
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
👁 378