# Tutorial :how to replace the backslash in php to xml?

### Question:

I'm trying to create a xml file from php.... it is not work properly... when i eentered \notepad\text ,it creates in xml file as otepad ext....

what's the solution for this problem? can i use any function to this?

### Solution:1

When you write it this way:

echo "\notepad\text";  

\n will be interpreted as a newline and \t as a tab.

Try single quotes:

echo '\notepad\text';  

or escape the backslash characters:

echo "\\notepad\\text";  

### Solution:2

You can replace them with the constant DIRECTORY_SEPARATOR.

Or just use forward slashes and

$string = str_replace('/', DIRECTORY_SEPARATOR,$string);  

To make using this constant less cumbersome, you can do this

define('DS', DIRECTORY_SEPARATOR);  

Joomla does this.

If you want to skip the constant all together, you can probably also add an extra backslash to escape the escape character.

As for using a function, you can wrap that str_replace() above in a function.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »