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: 11,271
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.

Txp Builders – finely-crafted code, design and Txp

Offline

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

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website 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: 11,271
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.

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: 11,271
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.

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: 11,271
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.

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

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

Board footer

Powered by FluxBB