ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Parse error: syntax error, unexpected T_ENDIF - but not what you think!!

May 11, 2013 7:25pm

Subscribe [2]
  • #1 / May 11, 2013 7:25pm

    eevolution

    30 posts

    I’m really struggling with what I can only put down to being an EE or PHP error. I have the below code which is thowing an error when ran. It doesn’t matter if its in a snippet or simply in its own template with no other code.

    <div class="langselect">
            <ul class="no-js">
                <li>
                    <a href="#" title="{gv_click_to_select_language_{language}}" class="clicker">{gv_theme_url}imgs/flag_{language}.png</a>
                    <ul>
                        <li><a href="http://www.site.com/{if">{gv_theme_url}imgs/flag_en.png EN</a></li>
                        <li><a href="http://fr.site.com/{if">{gv_theme_url}imgs/flag_fr.png FR</a></li>
                        <li><a href="http://de.site.com/{if">{gv_theme_url}imgs/flag_de.png DE</a></li>
                        <li><a href="http://sp.site.com/{if">{gv_theme_url}imgs/flag_sp.png SP</a></li>
          <li><a href="http://it.site.com/{if">{gv_theme_url}imgs/flag_it.png IT</a></li>
                     <li><a href="http://po.site.com/{if">{gv_theme_url}imgs/flag_br.png PO</a></li>
             </ul>
                </li>
            </ul>
        </div>

    When the page is loaded I get the following error:

    Parse error: syntax error, unexpected T_ENDIF in /home/blah/public_html/blah/adminfolder/expressionengine/libraries/Functions.php(684) : eval()'d code on line 9

    However, when I take out any two lines or reduce the amount of if statements it works fine. It can be any if statements just needs to be a set quantity to work.

    So to debug I have edited the Functions.php file evaluate function to the following:

    echo $str;
      return eval('?'.'>'.$str.'<?php ');  
      $x = eval('?'.'>'.$str.'<?php ');     
      if($x === false) {
       $timestamp = date("m-d-Y H:i:s");
       $msg = "Timestamp:".$timestamp."\n".$str;
       $fp = fopen("/tmp/evaluate_function.txt", 'a');
       fwrite($fp, $msg . "\n");
       fclose($fp);
       exit;
     } else {
       return $x;
    }

    Nothing gets added to /tmp/evaluate_function.txt. The echo however, does output in the browser. but it has some strange code in there:

    <ul>
                        <li><a href="http://www.site.com/about/test">https://www.site.com/themes/site_themes/v4/imgs/flag_en.png EN</a></li>
                        <li><a href="http://fr.site.com/about/test">https://www.site.com/themes/site_themes/v4/imgs/flag_fr.png FR</a></li>
                        <li><a href="http://de.site.com/about/test">https://www.site.com/themes/site_themes/v4/imgs/flag_de.png DE</a></li>
                        <li><a href="http://sp.site.com/about/test&lt?php">https://www.site.com/themes/site_themes/v4/imgs/flag_sp.png SP</a></li>
          <li><a href="http://it.site.com/about/test">https://www.site.com/themes/site_themes/v4/imgs/flag_it.png IT</a></li>
                     <li><a href="http://po.site.com/about/test&lt?php">https://www.site.com/themes/site_themes/v4/imgs/flag_br.png PO</a></li>
             </ul>

    I mean what the hell is that on the last row!!!! <?php code being injected. It doesn’t show if I get rid of the top two li’s (or any combination)

    Please can someone try this simple copy/paste test and let me know if you get the same error and any recommendations of things to try.

    Would also be interested in an alternative solution to what the code is doing, when someone clicks the flag/link it redirects with all the same segments.

    Tim

     

  • #2 / May 11, 2013 7:37pm

    eevolution

    30 posts

    ... gets more interesting….

    When this is visited via a URL with only one segment it shows

    <div class="langselect">
            <ul class="no-js">
                <li>
                    <a href="#" title="click to select a different language" class="clicker">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_en.png</a>
                    <ul>
                        <li><a href="http://www.site.com/test">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_en.png EN</a></li>
                        <li><a href="http://fr.site.com/test">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_fr.png FR</a></li>
                        <li><a href="http://de.site.com/test">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_de.png DE</a></li>
                        <li><a href="http://sp.site.com/test">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_br.png PO</a></li>
             </ul>
                </li>
            </ul>
        </div>

    ... have no idea where the random missing ones go. When running the same template group with /blah in segment 2 it crashes with the error above. I think I’m going completely mad. Never seen anything like this in the 10+ years of PHP development, please help.

  • #3 / Jun 10, 2014 6:07am

    Origin Media

    20 posts

    Did you ever solve this? I am having this exact same problem now…

  • #4 / Jun 10, 2014 6:00pm

    eevolution

    30 posts

    I solved it… two ways. The first was a quick fix to this a year ago and then another solution last month which it happened again and completely forgot how I did it originally.

    Initial solution:
    - I created a new variable in the index.php file with the following code (at the top of the file)

    $request = parse_url($_SERVER['REQUEST_URI']);
    $path = $request["path"];
    
    $result = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');
    
    $result = explode('/', $result);
    $max_level = 10;
    while ($max_level < count($result)) {
        unset($result[0]);
    }
    
    $result = '/'.implode('/', $result);
    
    $assign_to_config['global_vars']['full_segment']=$result;

    Then in the template using the following code:

    <li><a href="http://www.site.com/{full_segment}">https://www.site.co.uk/themes/site_themes/v4/imgs/flag_en.png EN</a></li>

    ————————————————————————————

    The second way I found last month when it cropped up in another solution was:

    {if "{segment_1}"}/{segment_1}{/if}{if "{segment_2}"}/{segment_2}{/if}{if "{segment_3}"}/{segment_3}{/if}{if "{segment_4}"}/{segment_4}{/if}{if "{segment_5}"}/{segment_5}{/if}

               
    The code can be in-line and works on pages with lots of statements.

    Good luck.

    Tim

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases