Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » General discussions
  3. » Php

#1 2008-12-01 18:48:24

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Php

Hi is their any reason why this code would through up this error:

Parse error: syntax error, unexpected $end in /home/driz/public_html/admin/publish/taghandlers.php(2804) : eval()’d code on line 4
This site is not fully compatible with Internet Explorer! But, if you want to go in anyway, be our guest.
Parse error: syntax error, unexpected ‘}’ in /home/driz/public_html/admin/publish/taghandlers.php(2804) : eval()’d code on line 2

Parse error: syntax error, unexpected ‘}’ in /home/driz/public_html/admin/publish/taghandlers.php(2804) : eval()’d code on line 2

<txp:php>
$warned = isset($_COOKIE['warned']) ? $_COOKIE['warned'] : $_GET['warned'];
if(strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") && $warned != 'true'){
</txp:php>
<html>
	<head>
		<title>IE Warning!!!</title>
	</head>
	<body>
		This site is not fully compatible with Internet Explorer!  But, if you want to <a href="<txp:php> echo $_SERVER['PHP_SELF']; </txp:php>?warned=true">go in anyway</a>, be our guest.
	</body>
</html>
	<txp:php>
}else{
	if(!isset($_COOKIE['warned'])){
		setcookie('warned', 'true');
	}
	</txp:php>


PAGE CONTENT

	<txp:php>
}
</txp:php>

~ Cameron

Offline

#2 2008-12-01 18:54:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,463
Website GitHub

Re: Php

FAQ ?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#3 2008-12-01 19:17:53

wet
Developer Emeritus
From: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,421
Website GitHub Mastodon

Re: Php

You cannot use <txp:php> like blocks of <?php ... ?> with intermingled HTML. Each single <txp:php>...</txp:php> block must be valid, self-contained PHP in itself.

Offline

#4 2008-12-01 20:17:09

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

wet wrote:

You cannot use <txp:php> like blocks of <?php ... ?> with intermingled HTML. Each single <txp:php>...</txp:php> block must be valid, self-contained PHP in itself.

Why not? How am i meant to get around this then?


~ Cameron

Offline

#5 2008-12-01 20:20:42

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Php

FAQ

Offline

#6 2008-12-01 21:00:25

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

ruud wrote:

FAQ

The FAQ just says I can’t do it! It doesn’t say how I can use XHTML with my PHP in blocks!


~ Cameron

Offline

#7 2008-12-01 21:08:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,463
Website GitHub

Re: Php

driz wrote:

It doesn’t say how I can use XHTML with my PHP in blocks!

Yes it does, under “Escaping to XHTML” it says:

<txp:php>
if ($something) {
echo 'foo';
}
</txp:php>

Which in your case is:

<txp:php>
if(strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") && $warned != 'true') {
echo <<<EOS
<head>
<title>IE Warning!!!</title>
</head>
<body>
		This site is not fully compatible with Internet Explorer!  But, blah blah
</body>
EOS;
} else {
... and so on...
}
</txp:php>

Last edited by Bloke (2008-12-01 21:09:53)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#8 2008-12-01 21:15:22

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

This doesn’t make any sense at all! What does EOS mean? What does <<< mean?
How can I have HTML tags inside the <txp:php> tags are have you just done by accident?


~ Cameron

Offline

#9 2008-12-01 21:27:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,463
Website GitHub

Re: Php

driz wrote:

How can I have HTML tags inside the <txp:php> tags are have you just done by accident?

Mistake?? Moi?! ;-)

The <<< is called heredoc and it’s a shorthand way of including stuff like javascript and hunks of things you can’t be arsed to individually echo out line by line. It’s rather handy. I think it works with HTML tags but I’ve not tested it; I don’t see a reason it wouldn’t work.

If you want to include PHP variables inside a heredoc block though, you need to define it outside the block and then display it between braces like this: {$var_name} from inside. e.g.

<txp:php>
$link_name = $_SERVER['PHP_SELF'] . "?warned=true";
echo <<<EOS
<head>
<title>w00t</title>
</head>
<p>Here's some tags and crap.
And here's a link: <a href="{$link_name}">Click me</a>
Does that make sense?</p>
EOS;
</txp:php>

EDIT: removed bogus echo statement

Last edited by Bloke (2008-12-01 21:30:25)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#10 2008-12-01 21:49:56

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

Urgh this is messy and complicated, why won’t Txp let you have blocks of PHP like PHP does? This is really annoying!

Can I start an EOS and then end one, and then start another one within the same block?
e.g.

echo <<<EOS

HTML

EOS;

SOME PHP

echo <<<EOS

HTML

EOS;

Last edited by driz (2008-12-01 21:51:46)


~ Cameron

Offline

#11 2008-12-01 21:52:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,463
Website GitHub

Re: Php

driz wrote:

So what exactly does EOS mean? what does it do?

Read the PHP manual link I gave you and it gives examples. You can choose any name you like; I just chose EOS as an acronym for End Of Script.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#12 2008-12-01 22:00:35

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

This is what I have so far, its cutting my DECLARATION OFF!!!

<txp:php>
$warned = isset($_COOKIE['warned']) ? $_COOKIE['warned'] : $_GET['warned'];
if(strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") && $warned != 'true')
echo <<<EOS
<html>
	<head>
		<title>IE Warning!!!</title>
	</head>
	<body>
		This site is not fully compatible with Internet Explorer!  But, if you want to <a href="echo $_SERVER['PHP_SELF'];?warned=true">go in anyway</a>, be our guest.
	</body>
</html>
EOS;
}else{
	if(!isset($_COOKIE['warned'])){
		setcookie('warned', 'true');
	}
	echo <<<EOS
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml2.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

	<head profile="http://gmpg.org/xfn/11">

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="generator" content="Textpattern" />
		<meta name="description" content="hand-coded webprojects" />
		<meta name="keywords" content="Design, Development, XHTML, CSS, Web 2.0, Web Standards" />

		<title><txp:output_form form="title" /></title>

... rest of head here...

	</head>

	<body id="<txp:if_section name="default">home<txp:else /><txp:section /></txp:if_section>">

~ Cameron

Offline

#13 2008-12-01 22:11:06

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

Re: Php

Could this conflict with PHP in other forms??? If so this isn’t going to work, as I can’t <<< every single bit of PHP i have running throughout my site, Txp is supposed to make life easier not complicate it!


~ Cameron

Offline

#14 2008-12-01 22:20:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,463
Website GitHub

Re: Php

driz wrote:

This site is not fully compatible with Internet Explorer! But, if you want to <a href=“echo $_SERVER[‘PHP_SELF’];?warned=true”>go in anyway</a>, be our guest.

That won’t work. You are already “inside” a PHP echo statement (the one between <<<EOS... EOS;) so you can’t put another echo inside it. You need to set up the link ahead of time and include it within braces. See my example a few posts ago with the $link_name in it. That’s the exact mechanism (almost the exact code) you’ll need to do that bit.

Re your recent post, you don’t need to worry about it conflicting across forms because it only applies on a form by form basis. But having said that I don’t know if it’ll work if you put <txp:... /> tags inside the heredoc. You could try it. My guess is it will work, because I think TXP just does a text replace, but you’re getting into the intricacies of the parser there which is totally out of my depth, so someone else will have to point you in the right direction.

As for it cutting off your DECLARATION, is the companion EOS; — for the second heredoc block — right at the bottom of the code after the closing </html>? Once you’ve got rid of the error in your first heredoc block, the only other way it would be cutting it off early is if you have the exact sequence of characters EOS; in the very leftmost column of the stuff you want to print out. That’s not very likely but if you think your HTML may contain such a sequence of characters, choose something else unique as the heredoc delimiter (e.g. <<<DRIZ_RULEZ_PHP ... )

EDIT: and seriously consider Neko’s suggestion below. It might well save you a headache.

Last edited by Bloke (2008-12-01 22:23:53)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#15 2008-12-01 22:21:47

Neko
Member
Registered: 2004-03-18
Posts: 458

Re: Php

Just to add more noise and confusion: I’m sorry, couldn’t you just use a JS script that sets a cookie on a link (like a close div link) in combination with a conditional CSS served to IE only? :)

Offline

  1. Index
  2. » General discussions
  3. » Php

Board footer

Powered by FluxBB