如何查找和替换对象中的文本

I have an object looks like this: pastebin.com and I want to find every "a" and replace with underlined "a". I tried like : preg_replace("/(" . preg_quote("a") . ")/", "<u>$1</u>", $object); But it returns me a string not an object or array. How can I do it?

Currently you have a JSON string. What you have will work, but could have you inserting <u> tags into JSON keys, which you don't want.

How about first converting this JSON into an array, looping through the array, and updating each element with values that have had as replaced:

$arr = json_decode($json, true);
foreach($arr as &$elm){
    $elm = array_map(function($i){
        return preg_replace("/(" . preg_quote("a") . ")/", "<u>$1</u>", $i);
    }, $elm);
}

Demo