开发者

how to replace the backslash in php to xml?

开发者 https://www.devze.com 2022-12-28 12:25 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消