WordPress – str_replace() not working with the_category(‘, ‘)

In WordPress, this works fine to retrieve my article category

the_category(', ');

It returns

<a href="/ghost-stories/" rel="category tag">Ghost Stories</a>

But its not working with str_replace

echo str_replace("ghost-stories", "blog", the_category(', '));

I want it to return

<a href="/blog/" rel="category tag">Ghost Stories</a>

It’s not making any change