Forum


Replies: 5   Views: 2238
Searchandreplace by bland space does not work
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 21-02-2019 - 15:13

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.