PHP - Problem replacing new lines

i have a script that reads a html doc and i cannot find a function that allows me to replace an empty line for a “backspace”, i tried replacing but i still getting an empty line.
i also need a function that allows me to do the inverse, convert spaces into new lines. thanks you all any help will be apreciated.

for example a have this

name
telephone
address

and i want to get this:

name telephone address

it’s a html file with <pre> tags and no other tags between