Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#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
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
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 ( ‘&#160;’, ‘ ‘, $_title );
$_title = wordwrap ( $_title, 30, ‘<br />’ );
echo $_title;
[/quote]
Last edited by glenelkins (2009-10-20 08:59:36)
Offline
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
Pages: 1