Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-19 15:37:54

glenelkins
Member
Registered: 2008-08-28
Posts: 29

PHP Doesnt always work?

Hi

I use the <txp:php> tag quite alot

But iv just come accross the fact that not everything seems to work. For example, i want to use the title() function from textpattern and also the php function “wordwrap”

[code]
$_title = title(); // works fine
$_title = wordwrap ( $_title, 10, ‘<br />’ ); // doesnt seem to do anything
echo $_title; // workds fine but the wordwrap made no difference
[/code]

what is going on here? If i use the above code in a normal PHP application, it runs fine!

Offline

#2 2009-10-19 15:48:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: PHP Doesnt always work?

glenelkins wrote:

i want to use the title() function from textpattern … $_title = title();

One thing that might be tripping the code up is that when using TXP’s functions they always need at least one argument; an array of 'attribute' => 'value' pairs. If you’re not using any such parameters you should still send an empty array like this:

$_title = title(array());

Does that make the code perform any better?

Last edited by Bloke (2009-10-19 15:48:51)


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 2009-10-19 15:51:26

glenelkins
Member
Registered: 2008-08-28
Posts: 29

Re: PHP Doesnt always work?

nope no difference. the title() function is coming from iside a form thats listing an article. i would use <txp:title /> but i need to use wordwrap()

Offline

#4 2009-10-19 17:11:58

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: PHP Doesnt always work?

does it not work in any case? Is it not appending <br /> to the title at all? Have you tried set the cut attribute to true to force the wrap?

wordwrap ( $_title, 10, "<br />", true );

Offline

#5 2009-10-20 08:31:32

glenelkins
Member
Registered: 2008-08-28
Posts: 29

Re: PHP Doesnt always work?

hi

no it doesnt do anything

Offline

#6 2009-10-20 08:53:37

glenelkins
Member
Registered: 2008-08-28
Posts: 29

Re: PHP Doesnt always work?

actually i found the issue

the title() function seems to return the every space replaced with “ “

So the following code sorted it:

[quote] $_title = htmlspecialchars ( title ( array() ) ); $_title = str_replace ( ‘&amp;#160;’, ‘ ‘, $_title ); $_title = wordwrap ( $_title, 30, ‘<br />’ ); echo $_title;
[/quote]

Last edited by glenelkins (2009-10-20 08:59:36)

Offline

#7 2009-10-20 08:56:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: PHP Doesnt always work?

glenelkins wrote:

the title() function seems to return the every space replaced with #160;

Ah, the good old widow/no-widow. Glad you found it; would never have thought to look there. Odd that it returned every space with a 160 though — it’s only supposed to return it between the last two words.

Last edited by Bloke (2009-10-20 08:57:22)


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 2009-10-20 09:00:48

glenelkins
Member
Registered: 2008-08-28
Posts: 29

Re: PHP Doesnt always work?

most of the titles are only 2 words lol. they are names of actors. also, i forgot to mention the text must be re-encoded with htmlspecialchars_decode in case there are other characters like aposrophies or dots in the name

Offline

Board footer

Powered by FluxBB