2012-06-21 17:35
浏览 21

以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") {
    } else {
    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
    解决 无用
    打赏 举报

相关推荐 更多相似问题