服务器上出现意外的T_STRING错误,但本地主机上没有

时间:2013-12-11 10:46:06

标签: javascript php parsing

所以在我的localhost上我的网站运行正常,但是当我在我的工作场所的服务器上运行它(它有PHP 5.3.3)时,我不断收到意外的T_STRING错误。 我已经将问题精确定位到一个函数:exportXML(当我删除此功能时,网站正在运行)

有什么想法吗? 我确定我的代码是正确的..

Error:
Parse error: syntax error, unexpected T_STRING in /opt/www-abba/paintingtool/index.php on line 427 

FYI Line 427就是这一个:
            window.open( “数据:文本/ XML;字符集= UTF-8,” + XML);

代码(是的,这是.php文件中的JavaScript):

function exportXML(){
            var keys = Object.keys(jSelectedStation);
            //Trim all values
            for (var i = 0; i < keys.length; i++){
                if(jSelectedStation[keys[i]] !=null)
                {
                    jSelectedStation[keys[i]] = jSelectedStation[keys[i]].trim();
                }
                else
                {
                    jSelectedStation[keys[i]] = "";
                }
            }

            //STATION XML
            XML="<station stationNr='"+jSelectedStation.STATNAM+"'><definitionstat><admtyp>"+jSelectedStation.ADMTYP+"</admtyp><responsible>"+jSelectedStation.RESPONSIBLE+"</responsible><bildnam>"+jSelectedStation.BILDNAM+"</bildnam><stattyp>"+jSelectedStation.STATTYP+"</stattyp><stattel>"+jSelectedStation.STATTEL+"</stattel><statnr>"+jSelectedStation.STATNR+"</statnr><zonenr>"+jSelectedStation.ZONENR+"</zonenr><stattext>"+jSelectedStation.STATTEXT+"</stattext><xcoordinate>"+jSelectedStation.XCOORDINATE+"</xcoordinate><ycoordinate>"+jSelectedStation.YCOORDINATE+"</ycoordinate><refresh>"+jSelectedStation.REFRESH+"</refresh><groupid>"+jSelectedStation.GROUPID+"</groupid><position>"+jSelectedStation.POSITION+"</position><extra1>"+jSelectedStation.EXTRA1+"+</extra1><extra2>"+jSelectedStation.EXTRA2+"</extra2><extra3>"+jSelectedStation.EXTRA3+"</extra3><quittype>"+jSelectedStation.QUITTYPE+"</quittype><aliaslist><alias type='imelda'>"+jSelectedStation.IMELDA+"</alias></aliaslist><statcfg>"+jSelectedStation.STATCFG+"</statcfg></definitionstat><logic></logic><logicf></logicf><devices>";

            var keys = Object.keys(racks);
            for (var i = 1; i < keys.length; i++) //For all elements in Racks, print XML line
            { //1 to skip EMPTY
                dev = racks[keys[i]];
                if(dev.punkt[0] != undefined)
                {
                    currKrt=dev.punkt[0].y;
                }
                else
                {
                    console.log(dev);
                }
                XML+="<device statdev='"+keys[i]+"'><definitiondev><dvtyp>"+dev.type+"</dvtyp><bildnam>"+dev.bildnam+"</bildnam><responsible>"+dev.responsible+"</responsible><text>"+dev.text+"</text>";
                    if(dev.type == "I" || dev.type == "A")
                    {
                        XML+="<i_plaus_min>"+dev.extraProp[0]+"</i_plaus_min><i_plaus_max>"+dev.extraProp[1]+"</i_plaus_max><i_ala_min>"+dev.extraProp[2]+"</i_ala_min><i_ala_max>"+dev.extraProp[3]+"</i_ala_max><i_reference>"+dev.extraProp[4]+"</i_reference>";
                    }
                    else
                    {
                        XML+="<i_plaus_min>0</i_plaus_min><i_plaus_max>0</i_plaus_max><i_ala_min>0</i_ala_min><i_ala_max>0</i_ala_max><i_reference>0</i_reference>";
                    }
                XML+="<record>"+dev.record+"</record><extratext></extratext><quittype>M</quittype><punkt><kaartdev plaats='"+currKrt.substring(0,currKrt.indexOf(" "))+"'>";
                devpkt = 1;
                    for (var x=0; x < dev.punkt.length; x++)
                    {
                    if(dev.punkt[x] != undefined)
                        {
                        if(dev.punkt[x].y != currKrt)
                        {
                            currKrt = dev.punkt[x].y;
                            XML+="</kaartdev><kaartdev plaats='"+currKrt.substring(0,currKrt.indexOf(" "))+"'>";
                        }
                        //console.log("["+dev.punkt[x].y.substring(dev.punkt[x].y.indexOf(" ")+1,dev.punkt[x].y.length)+"]");
                        XML+="<devpkt id='"+devpkt+"'><pkttyp>"+dev.punkt[x].y.substring(dev.punkt[x].y.indexOf(" ")+1,dev.punkt[x].y.length)+"</pkttyp><pktcons>100</pktcons><bitnrk>"+dev.punkt[x].x+"</bitnrk><bitstatus>0</bitstatus></devpkt>";
                        devpkt++;
                        // if(devpkt>16){alert("More then 16 pkts, THIS IS MADNESS");throw "Stopping execution because not all punkts are defined";}
                        }
                    else
                        {
                            alert("Not all punkt for " + keys[i] + " are defined. \nPlease define punkt " + (x+1));
                            throw "Stopping execution because not all punkts are defined";
                        }
                    }
                XML+="</kaartdev></punkt></definitiondev><refdev refnam='";
                // Refdev substring
                if(dev.refdev.indexOf("-") > -1)
                {
                    XML += dev.refdev.substring(0,dev.refdev.indexOf("-")) + "'/></device>";
                }
                else
                {
                    XML += dev.refdev+"'/></device>";
                }
            }
            XML += "</devices><iodef></iodef></station>";
            window.open("data:text/xml;charset=utf-8,<?xml version='1.0' encoding='UTF-8'?>"+XML);
            // window.open("data:text/xml;charset=utf-8,<?xml version='1.0' encoding='UTF-8'?>"+XML.innerHTML,"ABBA XML","width=800,height=600");
            }

3 个答案:

答案 0 :(得分:2)

可能你在服务器上有short_open_tag = On,所以<?xml被解析为php代码启动。

通过php.ini或.htaccess设置short_open_tag = Off

答案 1 :(得分:1)

这是导致错误的行:

window.open("data:text/xml;charset=utf-8,<?xml version='1.0' encoding='UTF-8'?>
                                         ^                                    ^

如果您启用了short_open_tag配置(请查看phpinfo()输出以查看),那么PHP将尝试将<??>内的所有内容解析为PHP代码。在这种情况下,<?xml被视为PHP代码块的开头,这就是产生错误的原因。

答案 2 :(得分:0)

我也面临同样的问题。这是由short_open_tag开始的。请在.htaccess中尝试此操作。它对我有用

php_value short_open_tag 0