The application most likely has functions to write start tags, end tags, and escape characters already.
This method supplies escape characters for all invalid characters in the URI.
Make sure to escape characters if needed since you are modifying actual PHP code.
The extra single quotes are escape characters.