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 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了