PHP equivalent of Python's `str.format` method? -


is there equivalent of python str.format in php?

in python:

"my {} {} cat".format("red", "fat") 

all see can in php natively naming entries , using str_replace:

str_replace(array('{attr1}', '{attr2}'), array('red', 'fat'), 'my {attr1} {attr2} cat') 

is there other php's native alternatives?

sprintf closest thing. it's old-style python string formatting:

sprintf("my %s %s cat", "red", "fat") 

Comments