Question

Encoded

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

Asked by Encoded 3 months ago php

Answers

Hugues
1

Best Answer

Best Answer

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

See here for more details: www.php.net

by Hugues 3 months 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 3 months ago

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

by unregistered 3 months 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 3 months ago

Answer this question

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

0 errors found:

 
0