Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: [archived] sab_substr
Any idea why I’m not getting apostrophes, but instead getting: no '. I’ve dropped in $thing = strip_tags($thing); but I don’t think that’s the issue here. I’ve also disabled ‘nowidow’ option in the TXP preferences. No luck. I don’t know enough PHP to get my head around this problem on my own.
Last edited by bullseyeinteractive (2008-03-12 18:37:36)
Offline
Re: [archived] sab_substr
Problem found. The preg_replace was missing the ‘s’ modifier, needed to treat the entire string as a single line. New version uploaded.
“substr” is not safe for use with UTF-8 strings, because it works on byte level instead of on character level, which for UTF-8 means a string can be split inside a multi-byte character and that results in invalid UTF-8.
Offline
Re: [archived] sab_substr
Ruud… uploaded the new version and I’m still seeing the ascii codes for “ and ‘. Is there something I haven’t set up correctly in Textpattern itself? I’ve gone through and replaced the “ and ‘ in the articles thinking that might have been a problem but no luck there either.
Offline
Re: [archived] sab_substr
sab_substr currently works only on normal text, not on HTML escaped text.
To make it work with HTML escaped text with markup, yet still make the limit attribute work accurately and have the resulting substring be valid HTML, that’s non-trivial and certainly a lot slower.
If you don’t mind tags getting stripped and risk of invalid HTML and inaccurate limits, you could add strip_tags and remove escape_output as a fast solution.
Offline
Re: [archived] sab_substr
The strip_tags flip fixed it. And I don’t mind the tags getting stripped because I’m only using it for the title tag now. Thanks.
Offline
Re: [archived] sab_substr
ruud, just consider updating your help file sometime for the noobies, it did cause a problem earlier where someone copied it verbatim. Here’s what it says:
Example:
<sab_substr limit="10" trail="..."><txp:title /></sab_substr>
will output “long string…”, assuming the title is ‘long string title’.
Should be:
<txp:sab_substr limit="10" trail="..."><txp:title /></txp:sab_substr>
Also, when I use it as suggested in the help file, I get this crappy result. Is this the same limitation that has been discussed in this thread regarding escape characters?
EDIT: OK, I turned the no widow option off in Admin->Prefs (this option never worked to begin with, unfortunately, see here). Even with this option off, I still get this bad result. What’s the easiest way around this? I really don’t want to type in ascii codes for apostrophes and such. Is there a plugin to do this too? It would help, because I notice my RSS feed has these characters in it sometimes (depending on the reader).
Last edited by aswihart (2008-03-15 00:12:28)
Offline
Re: [archived] sab_substr
For those looking for another plugin that may work better than this (it did for me) try aam_typogrify. It doesn’t do what this plugin does – making substrings and adding ellipses, but it accomplishes a similar improvement in typographical appearance by preventing “widowed” words (single words on the final line of a title, paragraph, etc…) on any block of text.
Last edited by aswihart (2008-03-15 12:22:09)
Offline
Re: [archived] sab_substr
I’ll update the help and I’m seriously considering writing a substring plugin that can deal with XHTML properly.
Offline
Offline
Re: [archived] sab_substr
Probably brand new.
Offline
Re: [archived] sab_substr
I’ve updated sab_substr to correct the help text.
And I’ve written a small plugin that, unlike sab_substr, can cut an XHTML string properly: rvm_substr
Offline
#42 2009-03-03 16:37:12
- paulyoung
- Member
- Registered: 2008-06-21
- Posts: 10
Re: [archived] sab_substr
Feature request!
Remove characters from the end by using negative numbers. eg. to remove a file extension with Podcast.mp3 as the file name
<txp:sab_substr limit="-4"><txp:file_download_name /></txp:sab_substr>
I’m currently doing this instead if it helps:
<txp:php> $name = $thisfile['filename']; substr_replace($name ,"",-4); echo $name; </txp:php>
Offline