List Info

Thread: Newline being inserted after plugin




Newline being inserted after plugin
user name
2007-10-09 22:44:27
I created a smarty function called  that
creates a
URL designed to go inside a <a href=""> -
for example:

<a href="{link_to_template
param1=xyz}">Blah</a>

This creates a cache php file with the following:

<a href="<?php echo
smarty_function_link_to_template(array('param1' =>
'xyz'), $this);?> 

">Blah</a>

There is a single blank line after the ?> (not two in the
code above,
I inserted one for readability).  This was never a problem
under
php4 - but moving the same site to php5 I get an error now:

Fatal error: Cannot use string offset as an array in ...

I verified the actual return value in the plugin does NOT
contain a
newline so it seems smarty is putting it in there.

Is there any way to prevent a plugin from automagically
inserting a
carriage return after the ?> or is there something else I
did?

Thanks,

Josh

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: Newline being inserted after plugin
user name
2007-10-10 08:22:45
Hello Josh,

I'm not sure whether this will do the trick, but I'd suggest
to try the 
strip modificator on the output...

Ciao Peggy


Josh Trutwin schrieb:
> I created a smarty function called 
that creates a
> URL designed to go inside a <a href="">
- for example:
> 
> <a href="{link_to_template
param1=xyz}">Blah</a>
> 
> This creates a cache php file with the following:
> 
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?> 
> 
> ">Blah</a>
> 
> There is a single blank line after the ?> (not two
in the code above,
> I inserted one for readability).  This was never a
problem under
> php4 - but moving the same site to php5 I get an error
now:
> 
> Fatal error: Cannot use string offset as an array in
...
> 
> I verified the actual return value in the plugin does
NOT contain a
> newline so it seems smarty is putting it in there.
> 
> Is there any way to prevent a plugin from automagically
inserting a
> carriage return after the ?> or is there something
else I did?
> 
> Thanks,
> 
> Josh

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: Newline being inserted after plugin
user name
2007-10-10 09:03:35
A new line is created after the ?> because PHP eats the
newline.

So, this (foo outputs 'FOO'):

TEST""TEST

is compiled to:

TEST"<?php echo foo(array(), $this);?>
"TEST

(see the newline inserted)

And the final output:

TEST"FOO"TEST

(no newline)


Josh Trutwin wrote:
> I created a smarty function called 
that creates a
> URL designed to go inside a <a href="">
- for example:
>
> <a href="{link_to_template
param1=xyz}">Blah</a>
>
> This creates a cache php file with the following:
>
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?> 
>
> ">Blah</a>
>
> There is a single blank line after the ?> (not two
in the code above,
> I inserted one for readability).  This was never a
problem under
> php4 - but moving the same site to php5 I get an error
now:
>
> Fatal error: Cannot use string offset as an array in
...
>
> I verified the actual return value in the plugin does
NOT contain a
> newline so it seems smarty is putting it in there.
>
> Is there any way to prevent a plugin from automagically
inserting a
> carriage return after the ?> or is there something
else I did?
>
> Thanks,
>
> Josh
>
>   

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: Newline being inserted after plugin
user name
2007-10-10 09:24:51
On Wed, 10 Oct 2007 09:03:35 -0500
Monte Ohrt <monteohrt.com> wrote:

> A new line is created after the ?> because PHP eats
the newline.
> 
> So, this (foo outputs 'FOO'):
> 
> TEST""TEST
> 
> is compiled to:
> 
> TEST"<?php echo foo(array(), $this);?>
> "TEST
> 
> (see the newline inserted)
> 
> And the final output:

Final output in the cache .php file or in the browser?  If
this is
how it should appear in the cached php I'm not seeing this
-
the .php cache has what you have above with a newline after
?>.
 
> TEST"FOO"TEST
> 
> (no newline)

Thanks - but what do I do to not get a php fatal error when
the
template is rendered?

Josh

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: Newline being inserted after plugin
user name
2007-10-10 09:30:29
That error has nothing to do with the newline, it has to do
with how 
PHP5 handles strings and arrays. Double check which line is
receiving 
the error, and see if there is something being accessed as
an array, 
when actually no array is present.

Josh Trutwin wrote:
> I created a smarty function called 
that creates a
> URL designed to go inside a <a href="">
- for example:
>
> <a href="{link_to_template
param1=xyz}">Blah</a>
>
> This creates a cache php file with the following:
>
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?> 
>
> ">Blah</a>
>
> There is a single blank line after the ?> (not two
in the code above,
> I inserted one for readability).  This was never a
problem under
> php4 - but moving the same site to php5 I get an error
now:
>
> Fatal error: Cannot use string offset as an array in
...
>
> I verified the actual return value in the plugin does
NOT contain a
> newline so it seems smarty is putting it in there.
>
> Is there any way to prevent a plugin from automagically
inserting a
> carriage return after the ?> or is there something
else I did?
>
> Thanks,
>
> Josh
>
>   

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: Newline being inserted after plugin - Still stumped
user name
2007-10-12 14:34:20
On Wed, 10 Oct 2007 09:30:29 -0500
Monte Ohrt <monteohrt.com> wrote:

> That error has nothing to do with the newline, it has
to do with
> how PHP5 handles strings and arrays. Double check which
line is
> receiving the error, and see if there is something
being accessed
> as an array, when actually no array is present.

Monte, thanks, but I'm still having trouble finding the
problem.

I have the contents of the cached .php file here:

http://intel2.
intrcomm.net/smarty.phps

Search for smarty_function_pb_link_to_template - the error
is on the
line after the second occurrence:

Fatal error: Cannot use string offset as an array
in
/httpd/208.42.183.71/usnl.intrcomm.net/html/templates/cache/
%%03^031^031BA0FD%%template-pb_nurse_list_12.php.php
on line 67

I ran this file through php -l (lint check) and it said
there were no
Synax errors.  But something has to be amiss because there
is another
use of the link_to_template function above this one that
works just
fine.

Also might be helpful:

http://intel
2.intrcomm.net/template.phps (the template)
http://intel
2.intrcomm.net/function.phps (the plugin definition)

Usually problems like this aren't too hard to find, but I've
looked
at it and another smarty wizard and we're both stumped.

Thanks,

Josh

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re:
user name
2007-10-12 15:03:33
Found the problem - it was in the  function, I
wasn't
correctly setting up my $items variable and the {foreach
from=$items item=nurse} loop was choking.

Thanks,

Josh

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )