Embed function in string (PHP)

software development

#1

How can I embed a function in a string. I’m trying to use concatenate a string with a function in the middle. So I’ll try to do “this string is “. strlen($somestring) .” characters long”.
I’d expect to get “this string is 5 characters long”. But I don’t get that. I get an “unexpected $” error. What am I missing?


#2

I think the problem is the strlen function returns an integer, and you have a string. If you used a function to convert it to a string, it may work.

I know the following works:
$result = strlen($somestring);
“this string is $results characters long”

I am not sure about “this string is strlen($somestring) characters long”

Jeff
www.walltowallstencils.com


#3

Any of these would print out, “Apple is a 5-letter word.”

$something = “Apple”;

print "$something is a " . strlen($something) . ‘-letter word.’;

$this = "$something is a " . strlen($something) . ‘-letter word.’;
print $this;

print 'Apple is a ’ . strlen(‘apple’) . ‘-letter word.’;