Skip to content

Advanced string replace in setValue in Update src/PHPWord/Template.php #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Esmeraldo
Copy link

When started using Phpword it saved me a lot of time as i needed to replace a template 
in docx using php. I had a minor issue when started using the setValue method. I found
that using Word, the program creates some tags that the str_replace couldn't detect.

I cracked a little bit the function, using some regular expressions in order to:

  1. Find the regular expressions commencing with '${' and ending with '}' (in my case i
       dropped the $ sign cause i needed to use the $ sign in my word file)
  2. With only that string, find and eliminate all the opening tags
  3. find and eliminate the closing tags in that string
    4. replace the old string (with garbage code) with the cleaned string
  4. output the _documentXML
  5. this is the piece of code I implemented if anyone is interested

Btw, great job with this tool it saved me a lot of time!

Consulate in the site: http://phpword.codeplex.com/workitem/49

When started using Phpword it saved me a lot of time as i needed to replace a template 
in docx using php. I had a minor issue when started using the setValue method. I found 
that using Word, the program creates some tags that the str_replace couldn't detect.

I cracked a little bit the function, using some regular expressions in order to:

1. Find the regular expressions commencing with '${' and ending with '}' (in my case i 
   dropped the $ sign cause i needed to use the $ sign in my word file)
2. With only that string, find and eliminate all the opening tags
3. find and eliminate the closing tags in that string
4. replace the old string (with garbage code) with the cleaned string
5. output the _documentXML
6. this is the piece of code I implemented if anyone is interested

Btw, great job with this tool it saved me a lot of time!

Consulate in the site: http://phpword.codeplex.com/workitem/49
@vdespa
Copy link

vdespa commented Oct 1, 2013

+1

@Progi1984 Progi1984 closed this Dec 15, 2013
@Progi1984
Copy link
Member

Sorry, I cleaned the repository and removed the develop branch after pushing differences to master branch. But all pull requests have been automatically closed.

Could you send back your pull request to master branch ?

@Progi1984
Copy link
Member

Just commited and pushed your pull request : 049c89d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants