Encoded

How do I also replace a variable within a string in PHP?

Asked by Encoded 2 years ago php


Hugues
1

Most Helpful

Most Helpful

 
You can use double quoted strings, variables in scope will be replaced automatically.

See here for more details: www.php.net

by Hugues 2 years ago

unregistered
0
 
$string = "My string";
$needle = "string";
$replace = "replaced var";
echo str_replace($needle,$replace,$string)

Is this what you want? Or this:
$var = 'special string';
echo "I'm echoing a $var";// Output: I'm echoing a special string

by unregistered 2 years ago

unregistered
0
 
Need more info. As stated is pretty vague.

by unregistered 2 years ago

unregistered
0
 
Need more information.

I assume your doing something more complicated than:

$var = 'paul';

echo 'this person is ill today: ' . $var;

by unregistered 2 years ago

Answer this question

How do I also replace a variable within a string in PHP?

0 errors found:

 
0