I need a to generate a string like this, Helpers\Name
.
I have a $prefix
that contains \\
like $prefix = "Helpers\\";
When I merge the strings like below, It returns a string with double backslashes instead of one!
$what_i_want = $prefix . 'Name'; // return Helpers\\Name
After that result, I tried to replace the double backslashes by one with str_repleca[]
and preg_replace[]
methods but it does not work!
Any solution will be appreciated.
Update: Here is my helper function in Laravel which I want to return what I want: Here is my helper function in Laravel which I want to return what I want:
public static function getModelsClassesByString[]
{
$path = app_path[];
$models = [];
$prefix = "App\\";
$results = scandir[$path];
foreach [$results as $result] {
if [$result === "." or $result === ".."] continue;
$filename = $prefix . $result;
$models[] = substr[$filename, 0, -4];
}
return $models;
}
the function return like below:
["App\\Admin", "App\\User",...]
Also, I really don't understand someone who could not help but let itself to destroy the question and my needs by down votes or destructor comments.
Hướng dẫn dùng php compact trong PHP
Định nghĩa hàm compact[] trong PHPHàm compact[] trong PHP nhận các biến làm các tham số. Mỗi tham số có thể là chuỗi chứa tên biến, hoặc một mảng các biến. ...
Hướng dẫn dùng catch errors trong PHP
Xin chào tất cả các mọi người, bài viết này mình xin trình bày về xử lý lỗi và Exception trong PHP, rất mong được sự theo dõi của mọi người1] Xử lý ...
Hướng dẫn dùng id hash trong PHP
Hàm hash[] sẽ mã hóa chuỗi truyền vào theo một thuật toán nhất định. Thuật toán mã hóa sẽ do người dùng cung cấp.Bài viết này được đăng tại ...
Hướng dẫn x++ in php - x++ trong php
Các toán tử so sánh, như tên của chúng ngụ ý, cho phép bạn so sánh hai giá trị. Bạn cũng có thể quan tâm đến việc xem các bảng so sánh loại, vì chúng hiển ...
Hướng dẫn get previous element in foreach php - lấy phần tử trước đó trong foreach php
Mảng của tôi:$arr = array[jan,feb,mar,apr,mei,jun,jul,agu,sep,okt,nov,des]; Sau đó, tôi làm một foreachforeach[$arr as $ar]{ echo $ar; } Điều đó sẽ xuất ...