Skip to content

Tag: php

preg_match accented characters

I have an issue using preg_match with php. I want my users to fill the Name field with only valid characters. Ex: no numbers or special chars. My site will eventually be bilingual but most of my visitors are french Canadians I prefer utf-8 for my encoding. So at the top of my document i have this tag : I

Determine if PHP files is Running as Part of a `phar` archive

Is there a way to determine, at runtime, if a PHP file is running as part of a phar archive? i.e., a native implementation might look something like this However, this might not work if the user has renamed the phar to have a different file extension, or symlinked the phar to remove the file extension. Answer…

Difference between EloquentModel::get() and all()

What is the difference between uses User::all() and User::get() on Eloquent? On Laravel API it describes only all() on EloquentModel.Maybe get() is described on EloquentBuilder. Answer User::all() and User::get() will do the exact same thing. all() is a static method on the EloquentModel. All it does is creat…

Correct way to add comments to a Regular Expression in PHP

I’m trying to add comments to make a regexp clearer But i get the warning Warning: preg_replace(): Unknown modifier ‘/’ in on line 280 How should i comment it? Answer This may not be the cleanest approach, but you could enclose each section in quotes and concatenate them. Something like this…

PHP wrong foreach code

What I have done wrong, foreach code written below, but it seems not working: What I have to change in this foreach code? Thanks Answer first line, custom is not a variable (could be copy and paste error) Then you are splitting a string using can array operator, you need to split that string first using: Then…

WordPress Woocommerce Redirect Argument

When I enable my site automatically show argument ?v= like this How can I fix this? Answer String to all urls ?v=XXXXXXXXXXXX. That URL is coming from standard base address setting in Woocommerce. When you choose geolocation with caching support for page, it will add that ?v=xxxx string because it’s cap…