256 Kilobytes

Answers > PHP

Type AnswersAsk and answer questions, if that is something that you want to do. Category All Tag PHPPHP: Hypertext Preprocessor is a scripting language used heavily in server-side development. PHP is frequently used for templating.

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
👁 556
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
👁 472
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
👁 437
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
👁 493
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
👁 485
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
👁 425
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
👁 539
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
👁 451
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
👁 435
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
👁 735
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
👁 375
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
👁 452
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
👁 349
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
👁 407
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
👁 335
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
👁 352
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
👁 331
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
👁 316
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
👁 455
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
👁 280
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
👁 308
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
👁 267
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
👁 329
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,149
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
👁 297
Profile Photo - Some Guy
Profile Photo - Some Guy

MoreHi! I'm just getting used to writing PHP scripts, and I was wondering if anyone knew whether or not it was possible to skip some optional paramet...
🗨 0
🐏 0
👁 258
Profile Photo - Some Guy
Profile Photo - Some Guy

MoreI have just started working on my company's server and have a question for you guys. Using PHP, is it possible to call a method on a new object i...
🗨 0
🐏 0
👁 254
Profile Photo - Some Guy

How to graph a parabola using JavaScript and/or PHP?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Some Guy

MoreI am working on a project and I am unsure of the software I will be using. I need to graph a parabola using JavaScript and/or PHP. Could anyone show m...
🗨 0
🐏 0
👁 271
Profile Photo - Some Guy

[PHP] Add leading zero to hexadecimal if not there?

Answers in Server-Side | By Some Guy

Published

Profile Photo - Some Guy

MoreHi, I am intern at a computer technician at my local computer store. I am working a server because we have ran into particular problem with out server...
🗨 0
🐏 0
👁 221
Profile Photo - Some Guy
Profile Photo - Some Guy

MoreI just started working on the Server-Side of things and am pretty new at this and would like some help. Anyone have experience with "base64_encod...
🗨 0
🐏 0
👁 297