how to replace the backslash in php to xml?
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?
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";
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.
精彩评论