如何在串联中显示来自函数调用的字符串?

I need to join/concatenate strings from a return of a function call, and from a variable without using the traditional concatenation ..

In this scenario, it should be displaying a url string.

Below is my actual code.

CODE:

$test = "{ config('app.url') }/{ $username }";
die(print_r($test));

Current Result:

{ config('app.url') }/testuser

Expected Result:

http://localhost:8000/testuser

You may read more about complex (curly) syntax in a quoted string, however you may achieve what you want with that code:

$test = "{${config('app.url')}}/{$username}";
die(print_r($test));

But I personally prefer:

$appUrl = config('app.url');
$test = "{$appUrl}/{$username}";
die(print_r($test));

Does that work for you?

It's not possible. You can only parse variables inside string. The only way is assigning function result to variable:

$url = config('app.url');
$test = "{$url}/{$username}";

You can read more about Variable parsing in strings

You can try the following way

<?php

$_ = function ( $v ) { return $v; };

function config($url)
{
    return $url;
}

$username = 'u_name';
echo "{$_( config('app.url') )}/{$username}";