Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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 2Parse 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
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
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
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
Re: Php
Offline
Re: Php
ruud wrote:
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
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
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
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
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
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
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