简体   繁体   中英

php outputs part of code without any echo

Here's my piece of code(full body code):

<body>
    <script type='text/javascript'>
        function AddEvent(Syear, Smonth, Sday, Eyear, Emonth, Eday, hallNumber){
            ...
        }
    </script>
    <?php
        function GetMonthByCoding($first , $second , $third) {
            ...
        }

        function GetDateByCoding($coding){
            ...
        }

        function GetDateFromLine($line){
            ...
        }

        $userid = '...';
        $magicCookie = 'cookie';

        $feedURL = "...";
        $sxml = simplexml_load_file($feedURL);

        foreach ($sxml->entry as $entry) {
            $title = stripslashes($entry->title);
            if ($title == "HALL") {
                $summary = stripslashes($entry->summary);
                $date = GetDateFromLine($summary);
                echo ("<script type='text/javascript' language='JavaScript'> AddEvent(" . $date['start']['year'] . ", " . $date['start']['month'] . ", " . $date['start']['day'] . ", " . $date['end']['year'] . ", " . $date['end']['month'] . ", " . $date['end']['day'] . "); </script>");
            }
        }
    ?>
  </body>  
  • AddEvent() is JavaScript function defined earlier.

    What I get in my browser is:
entry as $entry) { $title = stripslashes($entry->title); if ($title == "HALL") { $summary = stripslashes($entry->summary); $date = GetDateFromLine($summary); echo (""); } } ?>

Looks like it was an echo but as you can see there is no echo right in the middle of foreach.

Can anyone say what I am doing wrong?

PHP is not installed, or it is not enabled, or the file is not a .php file or the server has not been told to recognise it as a file to parse.

Try View Source and you should see all your PHP code. The only reason part of it shows up is because everything from <?php to the first > is considered by the browser to be an invalid tag.

I found the problem, it was in the name of variable sxml. I renamed it and the problem escaped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM