dqcj32855 2012-06-21 09:35
浏览 23
已采纳

以XML格式读取页面URL? 或者在XML文件中使用PHP

I have a flash element (I know, but please don't) with a settings.xml file.

One of the values in the XML file depends on the URL, so rather than having multiple instances of the flash folder, I want to do the following:

value="<?php $rest = substr(<?php echo curPageURL(); ?>, -2, -1) ?>"

I tried that in vain, but as you probably already knew, that won't work.

So I either need a way to write that in XML, or to allow that line of PHP within the XML file.

function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {
        $pageURL. = "s";
    }
    $pageURL. = "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL. = $ _SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL. = $ _SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}
  • 写回答

1条回答 默认 最新

  • doujie4787 2012-06-21 09:40
    关注

    You need two things for this to work:

    1. Your server would need to be configured to parse XML files as PHP files. If you're using Apache, that's something in your configuration similar to this:

      AddHandler application/x-httpd-php5s .xml
      
    2. You'd need to use valid PHP syntax, like so:

      value="<?php echo substr( curPageURL(), -2, -1); ?>"
      

      Assuming that curPageURL() is a function defined in PHP.

    Finally, you should ensure that the short_open_tag directive is set to Off in your php.ini configuration, or else PHP will throw syntax errors when it encounters XML opening tags, e.g. <?xml. This can be done in .htaccess with something similar to

    php_value short_open_tag Off
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部