首页 > 技术文章 > php中xml变量替换

stronger-xsw 2020-06-30 15:33 原文

代码如下:

private function transmitText($object, $content)
{
    $textTpl = "<xml>
                <ToUserName>%s></ToUserName>
                <FromUserName>%s></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType>%s</MsgType>
                <Content>%s></Content>
                </xml>";
    $result = sprintf($textTpl, 'ToUserName', 'FromUserName', time(), 'text','Content');
    return $result;
}

替换后打印$result如图:

推荐阅读