Jump to content

PHP Parse error: syntax error, unexpected '<'


thesunlover

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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. 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

 

 

 

Link to comment
Share on other sites

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.

  • Great Answer 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.