I have a array :
$arr = ['name', 'age', 'address'];
$impString = implode(',',$arr);
// result : "name','age','address"
The result I want: "'name','age','address'"
Help me please.
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
I have a array :
$arr = ['name', 'age', 'address'];
$impString = implode(',',$arr);
// result : "name','age','address"
The result I want: "'name','age','address'"
Help me please.
I have multiple HTML/CSS sites where I have classes added automatically due to a bug in an earlier version. Therefore my HTML files look currently like this:
<html class=" js cssanimations gecko win js js cssanimations gecko win js js cssanimations gecko win js js cssanimations gecko win js js cssanimations gecko win js js cssanimations gecko win js lang=de><head>
or like this:
<html class=" js cssanimations webkit chrome win js js cssanimations gecko win js js cssanimations webkit chrome win js js cssanimations gecko win js js cssanimations gecko win js js cssanimations gecko win js" lang="de"><head>
So those “phrases” are repeating:
js cssanimations gecko win js
or:
js cssanimations webkit chrome win js
I would like to write a regex in PHP where I replace those classes with an empty string. Here is what I´ve tried so far but it is not working at all:
private $replaceRegexes = [
'html-class-attributes' => [
'regex' => '/<html.*class=".*".*>/',
'replacement' => '<html lang="de">',
]
];
But /<html.*class=".*".*>/
is not working.
Can someone help me out and let me know the correct regex for deleting the classes inside the <html tag?
Would appreciate any help.
Thanks,
Chris
this is my code. when i remove the numbers inside the password the program runs just fine. is it okay to leave it without a password?
I am new to Laravel. I am using registerController in Laravel to create users . Users data are stored in Users table.
What I have tried is :
@extends('adminlte::auth.auth-page', ['auth_type' => 'register'])
@php( $login_url = View::getSection('login_url') ?? config('adminlte.login_url', 'login') )
@php( $register_url = View::getSection('register_url') ?? config('adminlte.register_url', 'register') )
@if (config('adminlte.use_route_url', false))
@php( $login_url = $login_url ? route($login_url) : '' )
@php( $register_url = $register_url ? route($register_url) : '' )
@else
@php( $login_url = $login_url ? url($login_url) : '' )
@php( $register_url = $register_url ? url($register_url) : '' )
@endif
@section('auth_header', __('adminlte::adminlte.register_message'))
@section('auth_body')<!-- comment -->
<?php $roles = DB::table('roles')->where('id','>',1)->get(); ?>
<div class="login-form">
<div class="container">
<div class="row ">
<div class="register-box">
<div class="register-box-header">
<p class="login-box-msg">{{!empty($type) && $type == 'Agronamist' ? 'Buyer' : ''}} REGISTRATION FORM</p>
</div>
<div class="register-box-body register_body">
<form method="POST" action="{{ route('register') }}" class="registerForm" enctype="multipart/form-data">
@csrf
@if(empty($type))
<div class="row">
<div class="col-md-12 text-center">
<div class="form-group has-feedback">
<select name="role" class="form-control" onchange='window.location.href=window.location.origin+"/register?role="+$(this).val();' required>
<option value="">Select a Role</option>
@foreach($roles as $role)
<option value="{{$role->id}}" {{(count($_GET)>0 && $_GET['role'] == $role->id) ? 'selected' : ''}}>{{$role->name}} </option>
@endforeach
</select>
</div>
</div>
</div>
@else
<input type="hidden" name="role" value="2">
<input type="hidden" name="type" value="{{$type}}">
@endif
@if(count($_GET)>0 && $_GET['role'] != '')
<?php $states = DB::table('states')->orderBy('name','asc')->get();?>
<div class="row">
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="First Name *" name="first_name" value="{{ old('first_name') }}" required>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Last Name *" name="last_name" value="{{ old('last_name') }}" required>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email *" required>
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control phoneMask" placeholder="Phone *" name="phone" value="{{ old('phone') }}" required>
<span class="glyphicon glyphicon-phone form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Address *" name="address" value="{{ old('address') }}" required>
<span class="glyphicon glyphicon-map-marker form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="password" class="form-control @error('password') is-invalid @enderror" name="password" placeholder="Password *" required autocomplete="new-password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
@error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="password" class="form-control" name="password_confirmation" placeholder="Retype password *" required autocomplete="new-password">
<span class="glyphicon glyphicon-log-in form-control-feedback"></span>
</div>
</div>
<div class="row">
<div class="col-md-3 col-xs-offset-4 submit_btn">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
</div>
</form>
Register Controller
<?php
namespace AppHttpControllersAuth;
use IlluminateHttpRequest;
use IlluminateAuthEventsRegistered;
use AppHttpControllersController;
use IlluminateDatabaseEloquentBuilder;
use AppUser,AppUserDetails,AppUserRoles,AppUserAddresses, Appmanager_group;
use IlluminateFoundationAuthRegistersUsers;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesValidator;
use CarbonCarbon;
use Auth;
use DB;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/';
public function __construct()
{
//$this->middleware('guest');
}
public function register(Request $request){
$this->validator($request->all())->validate();
// dd($this->validator($request->all())->validate());
event(new Registered($user = $this->create($request->all())));
if(array_key_exists('type', $request->all())){
return $this->registered($request, $user) ? : redirect('/buyersList/'.Auth::user()->id)->with('success','Registered successfully.');
}else{
return $this->registered($request, $user) ? : redirect($this->redirectPath())->with('success','Registered successfully. Please wait for the approval to access your account.');
}
}
//$this->guard()->login($user);
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'phone' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return AppUser
*/
protected function create(array $data)
{
$user = User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
My data is not inserting to users table,and the create function is not working when I dd($user) it. How to make my code working. What my page shows when I try to submit data is :
i have a form where people can upload pdfs
with fpdf I append those pdf and generate a new one.
this works ok, unless someone uploads a vertical aligned pdf.
is there a way I can determine which alignment a pdf has?
this is my code to append:
/* APPEND PDFs */
$files = [];
array_push($files, $upload_folder . '/' . $pdf_name);
if($new_path != 0 & $ext == 'pdf'){
array_push($files, $new_path);
}
if($new_path1 != 0 & $ext1 == 'pdf'){
array_push($files, $new_path1);
}
if($new_path2 != 0 & $ext2 == 'pdf'){
array_push($files, $new_path2);
}
if($new_path3 != 0 & $ext3 == 'pdf'){
array_push($files, $new_path3);
}
if($new_path4 != 0 & $ext4 == 'pdf'){
array_push($files, $new_path4);
}
if($new_path5 != 0 & $ext5 == 'pdf'){
array_push($files, $new_path5);
}
if($new_path6 != 0 & $ext6 == 'pdf'){
array_push($files, $new_path6);
}
pdf = new setasignFpdiFpdi();
// iterate over array of files and merge
foreach ($files as $file) {
$pageCount = $pdf->setSourceFile($file);
for ($i = 0; $i < $pageCount; $i++) {
$tpl = $pdf->importPage($i + 1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tpl);
}
}
// output the pdf as a file (http://www.fpdf.org/en/doc/output.htm)
$pdf->Output('F',$upload_folder . '/' . $pdf_name);
thanks a lot
i have a problem with sync callendar in plugin motopress booking with bookin.com.
Automatic import works very well on the plugin, however it does not automatically import the booking.com calendar
Is it possible to perform an automatic import?
I’m planning to build a traveling website. Which language should I choose PHP or Python?
Looking forward to your suggestions!
I am looking for a way to call the product tags description as a shortcode which could then be added in page builder like elementor. hope to get help here to solve my problem.
I found this snippet but it shows on shop page not on product tag pages
add_action( 'woocommerce_after_shop_loop_item', woocommerce_product_loop_tags', 5 );
function woocommerce_product_loop_tags() {
global $post, $product;
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}
I am trying to store store an author and genre into a Book. The way I’m trying to achieve this is by having an Author table, Genre table and a Book table. I want to store the foreign key for the author and genre into the books table.
I have created a form to store the needed information for the book. Within the form, there are two select tags and within them I loop through the authors and genres array. I use a store function in my BookController to validate the data that is being sent. After the validation, I store a new Book.
However, the foreign keys are not being stored in the database except for the primary key, title, blurb and timestamps.
Book Model
class Book extends Model
{
use HasFactory;
protected $fillable = [
'author_id',
'genre_id',
'title',
'blurb',
];
public function authors()
{
return $this->BelongsTo(Author::class);
}
public function genres()
{
return $this->BelongsTo(Genre::class);
}
}
Author Model
class Author extends Model
{
use HasFactory;
protected $fillable = [
'name',
];
public function book()
{
return $this->hasMany(Book::class);
}
}
Genre Model
class Genre extends Model
{
use HasFactory;
protected $fillable = [
'title'
];
public function book()
{
return $this->hasMany(Book::class);
}
}
BookController create()
public function create()
{
$authors = Author::all();
$genres = Genre::all();
return view('admin.book.create', ['authors' => $authors, 'genres' => $genres]);
}
BookController store()
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|max:255',
'authors' => 'required|array',
'genres' => 'required|array',
'blurb' => 'required',
]);
Book::create($validatedData);
return redirect()->route('admin.book.create');
}
Books table migration
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->id();
$table->foreignId('author_id');
$table->foreignId('genre_id');
$table->string('title');
$table->string('blurb');
$table->timestamps();
});
}
create.blade.php (create Book page)
<div class="flex justify-center">
<div class="flex justify-center border lg:w-1/4">
<div class="flex flex-col justify-center lg:w-2/4 gap-2">
<form action="{{ route('admin.book.store') }}" method="post">
@csrf
<div class="mb-2">
<h1 class="text-xl">Add Book</h1>
</div>
<div>
<label class="" for="title">Title</label>
<input name="title" class="w-10 border border-gray-400 w-full py-1 px-2" type="text">
</div>
<div>
<label class="" for="author">Author</label>
<select name="authors[]">
@foreach($authors as $author)
<option value="{{ $author->id }}">{{ $author->name }}</option>
@endforeach
</select>
</div>
<div>
<label class="" for="genre">Genre</label>
<select name="genres[]">
@foreach($genres as $genre)
<option value="{{ $genre->id }}">{{ $genre->title }}</option>
@endforeach
</select>
</div>
<div>
<label class="" for="blurb">Blurb</label>
<textarea name="blurb" id="" cols="18" rows="10"></textarea>
</div>
<div>
<button class="py-2 px-4 border" type="submit">Save</button>
</div>
</form>
</div>
</div>
</div>
Ihave these data in json format i want to get only Engish value Data seperate. Like only need english data: (Center Bore (mm) : 66.6, Offset (mm) : 45, OEM Compatible : Yes).
I also try to decode data and seperate all data friquently but not get perfact result.
attributes: [
{
"thibertPartNumber": "081019",
"attributeID": "ID_114",
"attributeNames": [
{
"languageCode": "EN",
"localizedValue": "Center Bore (mm)"
},
{
"languageCode": "FR",
"localizedValue": "Alésage (mm)"
}
],
"attributeValues": [
{
"languageCode": "EN",
"localizedValue": "66.6"
},
{
"languageCode": "FR",
"localizedValue": "66.6"
}
]
},
{
"thibertPartNumber": "081019",
"attributeID": "ID_115",
"attributeNames": [
{
"languageCode": "EN",
"localizedValue": "Offset (mm)"
},
{
"languageCode": "FR",
"localizedValue": "Décalage (mm)"
}
],
"attributeValues": [
{
"languageCode": "EN",
"localizedValue": "45"
},
{
"languageCode": "FR",
"localizedValue": "45"
}
]
},
{
"thibertPartNumber": "081019",
"attributeID": "ID_122",
"attributeNames": [
{
"languageCode": "EN",
"localizedValue": "OEM Compatible"
},
{
"languageCode": "FR",
"localizedValue": "EOM Compatible"
}
],
"attributeValues": [
{
"languageCode": "EN",
"localizedValue": "Yes"
},
{
"languageCode": "FR",
"localizedValue": "Oui"
}
]
},
]
And i want output to be:
Center Bore (mm) : 66.6
Offset (mm) : 45
OEM Compatible : Yes
Hey guys im currently making a music streaming app and its going real good so far, but i want to add the ability to be able to skip songs using the skip btn aka F9(Mac OS) and FN F8(Windows). I noticed that Soundcloud and other sites have done it
//1:
update_post_meta( $order_id, '_order_shipping', '313' );
//2:
$order = new WC_Order( $order_id );
$order->calculate_totals();
$order->save();
After executing code 2, code 1 becomes ineffective!
I use WordPress / Peepso / Buddypress. I want to build a redirect on the user profile.
example domain.tld / redirect
Now I need a PHP code that reads the profilurl and then redirects the user to the profile.
I have this piece of code
<? php echo $ user-> get_profileurl ();?>
anyone any idea? Thanks!
I looked around stackoverflow, there are lots of this kind of question. But I can’t seem to find what is missing in the code.
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocsbackendcasestraffictraffic-insert.php:95 Stack trace: #0 C:xampphtdocsbackendcasestraffictraffic-insert.php(95): PDOStatement->execute(Array) #1 C:xampphtdocsrouter.php(51): include_once('C:\xampp\htdocs...') #2 C:xampphtdocsrouter.php(9): route('/traffic-insert', '/backend/cases/...') #3 C:xampphtdocsroutes.php(24): post('/traffic-insert', '/backend/cases/...') #4 {main} thrown in C:xampphtdocsbackendcasestraffictraffic-insert.php on line 95
This error came after solving this:
PHP AJAX – data update/edit inserts as new data instead of updating
Here is the code:
<?php
include('./backend/config/connection.php');
include('./backend/config/function.php');
if( isset($_POST["traffic_operation"]) ) {
if( isset($_POST["traffic_operation"]) == "Add" ) {
$traffic_doc = '';
if( $_FILES["traffic_doc"]["name"] != '') {
$traffic_doc = upload_image();
}
$statement = $connection->prepare('INSERT INTO traffic_violations (
plateNumber,
carModel,
carColor,
violationType,
ownerGender,
violationDateTime,
violationLocation,
workingShift,
violationAction,
violationStatement,
cccEmployee
) VALUES (
:plate_number,
:car_model,
:car_color,
:violation_type,
:owner_gender,
:violation_date,
:violation_location,
:working_shift,
:violation_action,
:traffic_doc,
:ccc_employee
)
');
$result = $statement->execute(
array(
':plate_number' => $_POST["plate_number"],
':car_model' => $_POST["car_model"],
':car_color' => $_POST["car_color"],
':violation_type' => $_POST["violation_type"],
':owner_gender' => $_POST['owner_gender'],
':violation_date' => $_POST['violation_date'],
':violation_location' => $_POST['violation_location'],
':working_shift' => $_POST['working_shift'],
':violation_action' => $_POST['violation_action'],
':traffic_doc' => $traffic_doc,
':ccc_employee' => $_POST['ccc_employee']
)
);
if( !empty($result) ) {
echo '<script>alert("Traffic Violation Added")</script>';
}
}
if( $_POST["traffic_operation"] == "Edit" ) {
$traffic_doc = '';
if( $_FILES["traffic_doc"]["name"] != '') {
$traffic_doc = upload_image();
} else {
$traffic_doc = $_POST['hidden_user_image'];
}
$statement = $connection->prepare('UPDATE traffic_violations SET
plateNumber = :plate_number,
carModel = car_model,
carColor = car_color,
violationType = violation_type,
ownerGender = owner_gender,
violationDateTime = violation_date,
violationLocation = violation_location,
workingShift = working_shift,
violationAction = violation_action,
violationStatement = traffic_doc,
cccEmployee = ccc_employee,
WHERE id = :id'
);
$statement->execute(
array(
'id' => $_POST["violation_id"],
':plate_number' => $_POST["plate_number"],
':car_model' => $_POST["car_model"],
':car_color' => $_POST["car_color"],
':violation_type' => $_POST["violation_type"],
':owner_gender' => $_POST['owner_gender'],
':violation_date' => $_POST['violation_date'],
':violation_location' => $_POST['violation_location'],
':working_shift' => $_POST['working_shift'],
':violation_action' => $_POST['violation_action'],
':traffic_doc' => $traffic_doc,
':ccc_employee' => $_POST['ccc_employee']
)
);
echo 'Traffic Violation Updated';
}
}
?>
I want to update every field in a specific table when running a migration that if it is ''
to be updated with NULL.
I have set one of the fields in db to ''
so I can test it.
I am getting an error when running that specific migration:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘DoctrineMigrationsVersion20211129141541’ for key ‘PRIMARY’
And my migration file:
final class Version20211129141541 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('UPDATE post SET context=NULL WHERE context=""');
$this->addSql('UPDATE post SET info=NULL WHERE info=""');
}
public function down(Schema $schema): void
{
}
}
Is this anyway the right approach?