Q: using str_replace to replace braket '{'?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
 From example in the book 'Programming PHP' (O'Reilly) (p.305)

$theKey = 'DESTINATION';
$target = '{' . $theKey . '}';
$inValues[$theKey] = 'some.php';

//$theTemplate = str_replace("\", $inValues[$theKey],               
//$theTemplate = str_replace("", $inValues[$theKey],               
$theTemplate = str_replace($target, $inValues[$theKey], $theTemplate);


First commented line is from book example but not working.
Second one is also not working too. It replaces string and left '{}'. So  
result is ''
Third one is my solution and it is working. It gives 'some.php'

But I think there is some way to just use str_replace alone.

Thank you

Sean Kim

Re: Q: using str_replace to replace braket '{'?

.oO(Sean Kim)

Quoted text here. Click to load it

In a double-quoted string the { cannot be escaped. Try this:

$theTemplate = str_replace('', $inValues[$theKey],


Site Timeline