LMSouq

Knowledge Base

Browse Moodle Solutions

2108 solutions found

Page 23 of 106
0 votes
1 ans
3 views
Finding the number of days between two dates

How to find number of days between two dates using PHP?

general-dev Solved
PH
asked 1 month ago by PHP Ferrari
0 votes
1 ans
3 views
Show a number to two decimal places

What's the correct way to round a PHP string to two decimal places? $number = "520"; // It's a string from a database $formatted...

general-dev Solved
RI
asked 1 month ago by Rich Bradshaw
0 votes
2 ans
3 views
Converting a Postman request to curl

I am calling my Java webservice (POST request) via Postman in the following manner which works perfectly fine (i.e. I can see my records getting inserted into t...

php-dev Solved
CO
asked 1 month ago by Coder
0 votes
1 ans
3 views
How do I pass variables and data from PHP to JavaScript?

I have a variable in PHP, and I need its value in my JavaScript code. How can I get my variable from PHP to JavaScript? I have code that looks like this: ``...

php-dev Solved
MA
asked 1 month ago by Madara's Ghost
0 votes
1 ans
3 views
How do I strip all spaces out of a string in PHP?

How can I **strip** / **remove** all **spaces** of a **string** in PHP? I have a **string** like `$string = "this is my string";` The output sho...

php-dev Solved
ST
asked 1 month ago by streetparade
0 votes
1 ans
3 views
PHP | define() vs. const

In PHP, you can declare constants in two ways: 1. With `define` keyword ```PHP define('FOO', 1); ``` 2. Using `const` keyword...

php-dev Solved
DA
asked 1 month ago by danjarvis
0 votes
1 ans
3 views
PHP parse/syntax errors; and how to solve them

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often ea...

php-dev Solved
MA
asked 1 month ago by mario
0 votes
1 ans
3 views
What are the differences in die() and exit() in PHP?

What are the differences between `die()` and `exit()` functions in PHP? I think both have the same functionality, but I doubt there is something different in...

php-dev Solved
CO
asked 1 month ago by coderex
0 votes
1 ans
3 views
Create a folder if it doesn't already exist

I've run into a few cases with WordPress installs with [Bluehost][1] where I've encountered errors with my WordPress theme because the uploads folder `w...

general-dev Solved
SC
asked 1 month ago by Scott B
0 votes
1 ans
3 views
Formatting a number with leading zeros in PHP

I have a variable which contains the value `1234567`. I would like it to contain exactly 8 digits, i.e. `01234567`. Is there a PHP function for that?

php-dev Solved
AN
asked 1 month ago by Andromeda
0 votes
1 ans
3 views
Are PDO prepared statements sufficient to prevent SQL injection?

Let's say I have code like this: $dbh = new PDO("blahblah"); $stmt = $dbh->prepare('SELECT * FROM users where username =...

database Solved
MA
asked 1 month ago by Mark Biek
0 votes
1 ans
3 views
Error "Cannot use object of type stdClass as array"

I get a strange error using `json_decode()`. It decodes the data correctly (I saw it using `print_r`), but when I try to access to information inside the array...

php-dev Solved
DA
asked 1 month ago by Dail
0 votes
1 ans
3 views
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac

I installed node using homebrew (Mojave), afterwards php stoped working and if I try to run `php -v` I get this error: php -v dyld: Library not load...

php-dev Solved
PE
asked 1 month ago by petekaner
0 votes
1 ans
3 views
How to check if a string starts with a specified string?

I'm trying to check if a string starts with `http`. How can I do this check? $string1 = 'google.com'; $string2 = 'http://www.google....

php-dev Solved
AN
asked 1 month ago by Andrew
0 votes
1 ans
3 views
How to install a specific version of package using Composer?

I am trying to install a specific version of a package using Composer. I tried `composer install` and `composer require` but they are installing the latest vers...

php-dev Solved
GD
asked 1 month ago by gdaras
0 votes
1 ans
3 views
How can I remove a package from Laravel using PHP Composer?

What is the correct way to remove a package from Laravel using PHP Composer? So far I've tried: 1. Remove declaration from file *composer.json* (in th...

php-dev Solved
IG
asked 1 month ago by igaster
0 votes
1 ans
3 views
Sort array of objects by one property

How can I sort this array of objects by one of its fields, like `name` or `count`? Array ( [0] => stdClass Object (...

php-dev Solved
AL
asked 1 month ago by Alex
0 votes
1 ans
3 views
How can I capture the result of var_dump to a string?

I'd like to capture the output of [`var_dump`][1] to a string. The PHP documentation says; > As with anything that outputs its result directly to t...

php-dev Solved
MA
asked 1 month ago by Mark Biek
0 votes
1 ans
3 views
Preferred method to store PHP arrays (json_encode vs serialize)

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JS...

php-dev Solved
KY
asked 1 month ago by KyleFarris
0 votes
1 ans
3 views
How to find the foreach index?

Is it possible to find the `foreach` index? in a `for` loop as follows: for ($i = 0; $i < 10; ++$i) { echo $i . ' '; } `$i`...

database Solved
US
asked 1 month ago by user18334