dqcj32855 2012-06-21 17: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 17: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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作