thesunlover Posted April 23, 2022 Share Posted April 23, 2022 Hi, I've got a new php issue: "PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_articlelist.tpl.php on line 19" The line 19 is "<title>addquote('<?=$bbname?'.'>')addquote('<?=$navtitle?'.'>')</title>" I am the web admin and trying to find a php repair tool online but haven't got it yet. Would someone help me fix the code issue? Thank you very much in advance! nz Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 23, 2022 Share Posted April 23, 2022 (edited) Does this look right? <?=$bbname?'.'> <?=$navtitle?'.'> Edited April 23, 2022 by benanamen Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 Thanks benanamen for your reply! It was working fine under PHP 5x, but not working under PHP 7 and 8. Unfortunately I don't know how to fix it. Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 23, 2022 Share Posted April 23, 2022 You're not closing each php section properly. <?=$bbname?'.'> is improperly closing php. Think about the how you close a php section of an html document. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 23, 2022 Share Posted April 23, 2022 Or better yet: STOP going in and out of php mode. Stay in php mode and use echo to output your html. Consider this: echo "<title>$title</title> <span class='white'>$subtitle</span>"; A very simple mixture of html and php without leaving the php mode. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 23, 2022 Share Posted April 23, 2022 2 hours ago, thesunlover said: t was working fine under PHP 5x, but not working under PHP 7 and 8 Was "working" or was it just that the error wasn't being reported (because error reporting wasn't ON) and no one noticed the error? Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 1 hour ago, foxclone said: You're not closing each php section properly. <?=$bbname?'.'> is improperly closing php. Think about the how you close a php section of an html document. You must be right. What would be the solution for the issue? Thanks. Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 1 hour ago, ginerjm said: Or better yet: STOP going in and out of php mode. Stay in php mode and use echo to output your html. Consider this: echo "<title>$title</title> <span class='white'>$subtitle</span>"; A very simple mixture of html and php without leaving the php mode. Any suggestion to fix it? Thanks! Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 44 minutes ago, Barand said: Was "working" or was it just that the error wasn't being reported (because error reporting wasn't ON) and no one noticed the error? The web is totally down now under PHP 7 and 8 (5 is unavailable). It was running well under 5. Thanks. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 23, 2022 Share Posted April 23, 2022 3 hours ago, thesunlover said: 1_articlelist.tpl.php php syntax errors are reported on the line where php encounters something it cannot understand within the current context. the actual problem is usually prior to the line where the syntax error is reported. post lines 1-19 exactly as they are in the file, using this forum's <> menu button. also, since this is a template system of some type, there's no telling what exactly the meaning is of any of the characters we can see in that snippet of code, if the initial/final double-quotes are part of the code or added by the OP, or even if we are seeing all the characters because the code wasn't posted here as code. Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 1 minute ago, mac_gyver said: php syntax errors are reported on the line where php encounters something it cannot understand within the current context. the actual problem is usually prior to the line where the syntax error is reported. post lines 1-19 exactly as they are in the file, using this forum's <> menu button. also, since this is a template system of some type, there's no telling what exactly the meaning is of any of the characters we can see in that snippet of code, if the initial/final double-quotes are part of the code or added by the OP, or even if we are seeing all the characters because the code wasn't posted here as code. Very good point. Thank you! Here is the code: 1 <? if(!defined('IN_DISCUZ')) exit('Access Denied'); ?><html> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=<?=CHARSET?>" /> 4 <meta http-equiv="MSThemeCompatible" content="Yes" /> 5 <meta name="description" content="" /> 6 <meta name="keywords" content="" /> 7 <meta name="MSSmartTagsPreventParsing" content="TRUE" /> 8 <!-- --------------------------------------------------------- 9 10 11 COPYRIGHT ?Yidian.com. All Rights Reserved. 12 2006-03-30 socool.ca designed by dream 13 14 -------------------------------------------------------------- --> 15 <?include template('css'); ?> 16 <script type="text/javascript" src="include/common.js"></script> 17 addquote('<?=$url_redirect?'.'>') 18 19 <title>addquote('<?=$bbname?'.'>')addquote('<?=$navtitle?'.'>')</title> 20 <link href="include/mh_css_6.css" type="text/css" rel="stylesheet"> 21 </head> 22 <body> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 23, 2022 Share Posted April 23, 2022 the most likely cause are the short opening <? tags, on lines 1 and 15 in the posted code and everywhere else they are used, being disabled. you can attempt to make this 'work' by enabling them in your php.ini the ideal way to fix this would be to do a search/replace to change all the <? tags, which must be followed by at least one white-space character (which isn't shown on line 15, but then again you didn't follow my instructions for posting the code), but not the <?= tags, into full <?php tags. 1 Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 23, 2022 Share Posted April 23, 2022 Using a 2006 templated program, in all likelyhood, will need more than just fixing this section to work with php7.x or php8.x. A lot has changed in the last 16 years. I suggest you find something a lot more recent. Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 1 hour ago, foxclone said: Using a 2006 templated program, in all likelyhood, will need more than just fixing this section to work with php7.x or php8.x. A lot has changed in the last 16 years. I suggest you find something a lot more recent. I totally agree with you, but it needs time and money. Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 23, 2022 Author Share Posted April 23, 2022 1 hour ago, mac_gyver said: the most likely cause are the short opening <? tags, on lines 1 and 15 in the posted code and everywhere else they are used, being disabled. you can attempt to make this 'work' by enabling them in your php.ini the ideal way to fix this would be to do a search/replace to change all the <? tags, which must be followed by at least one white-space character (which isn't shown on line 15, but then again you didn't follow my instructions for posting the code), but not the <?= tags, into full <?php tags. Would you please give me some details about how to enable them in php.ini? Here is what I got, that I don't know if useful: short_open_tag bool Tells PHP whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).https://www.php.net/manual/en/ini.core.php Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 23, 2022 Share Posted April 23, 2022 1 hour ago, foxclone said: A lot has changed in the last 16 years not to the core php language. up to date php5 code, that doesn't use any now removed features, has a good chance of working as is. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 24, 2022 Share Posted April 24, 2022 21 minutes ago, thesunlover said: Would you please give me some details about how to enable them in php.ini? Here is what I got, that I don't know if useful: short_open_tag bool Tells PHP whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).https://www.php.net/manual/en/ini.core.php Yes well on your server, you need to find that setting in your php.ini file or add it if it's missing entirely. short_open_tag = On After a change like this you typically have to restart your webserver, depending on what you are running and the configuration. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 24, 2022 Share Posted April 24, 2022 there is apparently a “full_opening_tag” fixer as part of this tool - https://cs.symfony.com/ as always, make sure you have a complete, verified backup before making any changes to your code. Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 24, 2022 Author Share Posted April 24, 2022 8 minutes ago, mac_gyver said: there is apparently a “full_opening_tag” fixer as part of this tool - https://cs.symfony.com/ as always, make sure you have a complete, verified backup before making any changes to your code. I am going to learn it. Thank you much! Quote Link to comment Share on other sites More sharing options...
thesunlover Posted April 24, 2022 Author Share Posted April 24, 2022 It looks like that the setting is already set on. See this: [~/public_html]# grep short_open_tag php.ini ; short_open_tag short_open_tag = On Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 24, 2022 Share Posted April 24, 2022 to check what value php is using for the setting, create a .php script with a phpinfo(); statement in it and see what the line in the output shows for the short_open_tag setting. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 24, 2022 Share Posted April 24, 2022 If you make it a habit to use the long open tag this won't be a problem down the road. And - if you don't keep switching php modes you won't have to worried about php open tags except at the beginning of your script. Here is the last post of code you submitted. See if it makes sense to you how I converted your coding. Don't know what that addquote thing is but I assumed it was a Php function name. <?php if(!defined('IN_DISCUZ')) exit('Access Denied'); $code=<<<heredocs <html> <head> <meta http-equiv="Content-Type" content="text/html; charset="$CHARSET" /> <meta http-equiv="MSThemeCompatible" content="Yes" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="MSSmartTagsPreventParsing" content="TRUE" /> heredocs; echo $code; include template('css'); $code=<<<heredocs <script type="text/javascript" src="include/common.js"> </script> <link href='include/mh_css_6.css' type='text/css' rel='stylesheet'> heredocs; echo $code; addquote('$url_redirect'); echo " <title>"; addquote('$bbname'); addquote('$navtitle'); echo " </title> </head> <body>"; Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 24, 2022 Share Posted April 24, 2022 The way to verify this is to create a script that only has this in it <?php phpinfo(); Put this script in the root of your website and open it with your browser. At the top of the output you can verify which php.ini file is being read in. Then use the browser search to find the short_open_tag setting and verify that it is in fact set to On. This is not the only puzzling thing in the source code you provided, as it appears to me that some sort of template compilation system must be involved, but let's make sure that you haven't missed something in the configuration. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 24, 2022 Share Posted April 24, 2022 5 hours ago, foxclone said: You're not closing each php section properly. <?=$bbname?'.'> is improperly closing php. Think about the how you close a php section of an html document. A lot of you have missed the nature of the code. The code being quoted is in templates (notice the name.tpl.php). <title>addquote('<?=$bbname?'.'>')addquote('<?=$navtitle?'.'>')</title> Notice the use of the addquote() function. These templates must be compiled in some way. Really we don't have enough information about the original code, and what it is, and where it came from to understand what is going on. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 24, 2022 Share Posted April 24, 2022 Looking more closely, this is some sort of forum. Which one, and what version? I figured it out: https://en.wikipedia.org/wiki/Discuz! Was this the commercial version or free version? Is the source available somewhere? Looks like this page has some info on upgrading versions, and possibly links: https://discuz.tistory.com/entry/Comsenz-Discuz-X33-20170101-PHP7 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.