New answers tagged php
0 votes
Does a "clamp" number function exist in PHP?
Yes, from PHP8.6 clamp() is natively available and it is not limited to numbers - you can pretty much compare any data which is comparable as long as the boundaries are sensical. Demo var_export(...
2 votes
Accepted
How can I iterate through a JSON file with PHP and access the second element of the file?
You need to add a key to the loop, which you can then use to reference the next element. However, you'll run into an issue at the end of the loop, but that's also easily checked. foreach ($path->...
3 votes
Accepted
phpMyAdmin very slow when moving to version 8.3 and later
If I understand this correctly, xdebug is some kind of feature that is involved in the developer experience. Correct, it's for active debugging during development, usually when linked to an IDE. It's ...
0 votes
Do $wpdb->insert(..) and $wpdb->update(..) automatically sanitize data?
The documentation explains the process of protecting against SQL Injection here: https://developer.wordpress.org/reference/classes/wpdb/#protect-queries-against-sql-injection-attacks You have to ...
0 votes
Laravel Octane + Native Docker + WSL2: Extreme Performance Issues
No — 2–10 seconds is not normal for Laravel running on Docker + WSL2, especially when server processing time is only 300–400ms. This usually means the delay is happening outside Laravel, most likely ...
0 votes
Laravel Octane + Native Docker + WSL2: Extreme Performance Issues
You need to test the APP outside this setup completely to start eliminating one by one, which is the culprit here 1- Is the app in local dev with Docker + Redis slow like this? 2- Did you try on a ...
1 vote
How can I install the Composer dependency manager when its installer has issues with my php.ini file?
I had no idea there was a windows installer for composer. I'm glad the ini approach worked but there are a lot of other packages out there which could be useful to your project. Eventually, you'll ...
-2 votes
Fopen function opens JPEG image as text
Well, probably You might want to add a 'b' as last sign to the mode string as stated on a note to the fopen() documentation: Windows offers a text-mode translation flag ('t') which will transparently ...
0 votes
How to connect to a OPC-UA server from PHP?
Update 2026: there is now a native open-source PHP implementation. gianfriaur/opcua-php-client — the option the question was looking for: a pure PHP OPC UA client, no C/C++ wrapping, no exec(), no ...
0 votes
Filter files in DirectoryIterator output
In addition to the first answer, you can use CallbackFilterIterator for a simpler solution: <?php // set your path $path = ''; $filesObject = new RecursiveIteratorIterator(new ...
Advice
2 votes
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
figgyfarts is not alone in this. I've been doing the same thing for over 30 years and I don't consider it a problem.
Advice
1 vote
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
This depends what's causing you to switch languages. If you're hitting major problems with a given language, preventing you from implementing what you're trying to do, then that's a sign it's worth ...
Advice
1 vote
0 replies
0 views
When selecting data from a database, how would I put it into a HTML table with a PHP PDO connection?
Also just to note, that once you've done the fetchAll(), the result of that is you've got a standard PHP associative array to work with (as per the documentation). Therefore the fact that you used PDO ...
Advice
0 votes
0 replies
0 views
When selecting data from a database, how would I put it into a HTML table with a PHP PDO connection?
Also have a look at Show values from a MySQL database table inside a HTML table on a webpage
1 vote
Error while requesting server, received a non successful HTTP code [400] with response Body: O:8:"stdClass":1:{s:5:"error";s:16:"consent_required";}
This error means the DocuSign user has not granted consent for JWT impersonation. When using the JWT grant flow, DocuSign requires the user to grant consent before your app can request tokens on their ...
1 vote
Default value if variable not sets
Starting with PHP 7.4 you can use Null Coalescing Assignment Operator (php.net): In your code example: if (($p ??= "") == "a") doSomething(); If $p is null or unset then it's ...
Advice
0 votes
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
What made you decide to rewrite them, instead of finishing it off in the language you were already using? Knowing your motivation for doing that would help us understand the situation and how you ...
Tooling
0 votes
0 replies
0 views
Recommended tool for sending WordPress form data to REST APIs with Bearer Token auth?
Any HTTP client library like cURL or Guzzle will do this job
Advice
3 votes
0 replies
0 views
When selecting data from a database, how would I put it into a HTML table with a PHP PDO connection?
Where did you get stuck in your research so far? This is not a new problem
0 votes
How to enable my CodeIgniter controller to correctly identify ajax calls from FullCalendar4?
The is_ajax method is used to validate a request from your JS. controller if ($this->request->isAJAX()) { $email = $this->request->getPost('email'); return $this->response->...
0 votes
how to create wireguard keys solely with php?
If your are using php >=7.2, you may use sodium extension! <?php $keypair = sodium_crypto_box_keypair(); $publicKey = sodium_crypto_box_publickey($keypair); $privateKey = ...
Advice
1 vote
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
Thank you for the advice! I think the Java GUI path is least likely to work out. The PHP version could be nice for viewing the page from my phone (if I managed to host it on my Raspberry Pi), and the ...
Advice
1 vote
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
Thank you, that is some great advice!
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
Ok cool, as long as you can verify that internal communication is done strictly with the internal DNS names of each container then you should be fine and can rule out issues with the localhost TLD.
-1 votes
WordPress REST API: Large Image Uploads Not Reaching Backend Despite Proper PHP Settings
To resolve the issue where large image requests fail to reach the WordPress backend, the most effective fix is switching from JSON Base64 to Multipart Form Data. The Cause Large JSON payloads are ...
-2 votes
AJAX POST Browser History
I'd suggest using HTMX, which significantly facilitates using AJAX. It provides a hx-push-url attribute which would solve your problem. See https://htmx.org/attributes/hx-push-url/ for more ...
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
Communication between containers is done by using the container name*, e.g. http://s3mock:9090/ or http://elasticmq:9324. (*) I think it's the container name, I don't know for sure because our setup ...
Advice
10 votes
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
You don't. You code for fun because you want to learn things, not beause you want to complete projects. Once you've learned something, it's ok to move to something more interesting. Leave the boring ...
Advice
5 votes
0 replies
0 views
How do I stop rewriting my incomplete projects in different languages?
I've always tried to match the language to where the data exists and how it will be used. If I'm pulling information from a remote server and I want to make it available as a web-interface, then PHP, ...
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
Well, the fact is that localhost is a reserved TLD that will always route to the internal loopback address. That means that if you're expecting one container to communicate with another using that URI,...
0 votes
Multilingual routes with parameters
From what I know about laravel, it registers routes once at boot and doesn’t dynamically switch route paths per request. So if you do: __('routes.community') = "community" then only /...
0 votes
pecl install Mosquitto-alpha fails on macOS for lack of cjson/cJSON.h
cc -I. -I/private/tmp/pear/temp/Mosquitto -I/opt/homebrew/Cellar/php/8.5.3/include/php -I/opt/homebrew/Cellar/php/8.5.3/include/php/main -I/opt/homebrew/Cellar/php/8.5.3/include/php/TSRM -I/opt/...
0 votes
codeigniter returning false from models
You should never need to return false from a method which normally returns an array of rows. Potentially returning false would mean that downstream scripts would need to check for false before trying ...
Advice
1 vote
0 replies
0 views
How to have separate ContentSecurityPolicy.php for different environments in CI4?
In my understanding in CI4 you may set in the app/Config/ContentSecurityPolicy.php by using a conditional statement, such as: Put inside the public function __construct() block if (ENVIRONMENT === '...
0 votes
How to direct Print in PHP with select default printer from web application?
I see that this is a very old question and has probably been answered by the poster. But here is an answer anyone can use. The easiest way to print something under Windows, Linux, BSD, and Mac is to ...
0 votes
convert model Codeigniter into MySQL query
Your model method uses CodeIgniter's query builder methods to render the following raw SQL assuming $id is the integer value 1. SELECT * FROM `t_trx_activity_detail` WHERE `activity_detail_id` = 1 ...
Best practices
0 votes
0 replies
0 views
How to add SEO-friendly meta tags dynamically in WordPress using PHP?
You can add a PHP function in your theme that dynamically outputs SEO meta tags (description, Open Graph, Twitter tags) based on the current post/page, and hook it into WordPress using `wp_head` so it ...
Best practices
2 votes
0 replies
0 views
How to get into Laravel?
Getting overwhelmed with Laravel at the beginning is completely normal — it’s a big framework, and trying to understand everything at once can feel confusing. The good news is: you don’t need to learn ...
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
Thank you so much! This information is so hard to find if you don't already know what the solution is. If I understood correctly: Path style: https://s3.eu-central-1.amazonaws.com/BUCKET/FILE (...
0 votes
Convert seconds into days, hours, minutes and seconds
I modified the code from above to look like HTOP, 3 years 1 day, 05:20:00 function getSystemUptime() { $str = shell_exec("cut -d. -f1 /proc/uptime"); $uptime = floatval($str); $uptime = ...
Best practices
0 votes
0 replies
0 views
How to get into Laravel?
Read the docs. Use Laravel Herd for your dev environment. Do laracasts. Do codecourse. Sign up for Laravel-News. Checkout projects at Made with Laravel. Best sources.
Advice
1 vote
0 replies
0 views
URL format for AWS S3 network requests
Virtual hosted–style vs path-style URLs: https://stackoverflow.com/a/32609817/12763954 Note that path-style is now deprecated. The S3Client constructor accepts a use_path_style_endpoint option: ...
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
Everything is inside Docker containers. But that part is already sorted out. In fact, I'm also testing the S3 server directly with curl or aws commands to solve problems one by one. That's how I ...
-2 votes
WordPress Permalink Manager Pro: Filtered post_type_link shows correct URL but results in 404
The 404 occurs because Permalink Manager Pro does not treat filtered permalinks as the source of truth. WordPress can display the correct URL via filters like post_type_link, but the plugin resolves ...
Advice
0 votes
0 replies
0 views
URL format for AWS S3 network requests
How is the local service running? Is this in a virtual environment like Docker or Vagrant? If so, you might be bumping into an issue with the localhost TLD.
0 votes
How to load CF7 CSS & JS only when form is on the page
Here's my answer based on the others, but using the official documented filters and functions from CF7 to first turn off the enqueue, then turn it back on only for posts or pages that have the ...
Advice
0 votes
0 replies
0 views
How do you correctly enforce only one active row per user with Doctrine and PostgreSQL under concurrent requests?
logic and feeling should normally go together, so not only see but first of all feel the logic. you don't solve constraints. you define them, then you use a system that can guarantee them. if you're ...
Advice
0 votes
0 replies
0 views
How do you correctly enforce only one active row per user with Doctrine and PostgreSQL under concurrent requests?
If I understood you right, per each user-id (I assume it is unique) there can only be one subscription. This constraint must not be violated. This is what a relational database management system with ...
0 votes
Laravel custom command line package isn't running
This issue is caused by a namespace mismatch in your package, not the command itself. Laravel relies on PSR-4 autoloading, which is case-sensitive. In your package, the namespace defined in composer....
Top 50 recent answers are included
Related Tags
php × 1464015mysql × 233774
javascript × 131636
html × 123105
laravel × 117539
jquery × 98357
wordpress × 89168
arrays × 72438
ajax × 65798
codeigniter × 52995
sql × 49021
json × 40964
symfony × 37178
laravel-5 × 34591
forms × 31853
regex × 30586
apache × 27140
database × 26456
.htaccess × 24900
css × 23395
mysqli × 22644
curl × 22472
pdo × 22051
woocommerce × 19411
session × 19219