Hello,
You can use the previous method to accomplish what you need, but can't do it only in a single step, as there's no method to accomplish it directly. You need to:
1. Load the XML returned by the getDOCXPathQueryInfo method, this is a DOM object so you can manipulate it.
2. Remove the placeholder and get if there's a blank space before (or after if needed) the placeholder in the same tag or in the previous sibling (or next sibling if removing the space after the placeholder) and remove it as well.
3. Replace the source element by the new one using DOCXPath.
If you open a support ticket attaching a DOCX sample (https://www.phpdocx.com/support), the dev team will generate a custom code using it.
Some users with the same case of use, instead of adding blank spaces around the placeholder:
text $PLACEHOLDER$ text
they remove them in the template:
text$PLACEHOLDER$text
So the placeholder can be removed without needing to clear other blank spaces or replaced with a new text string with blank spaces at the beginning/end.
Regards.