Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » [archived] sab_substr

#31 2008-03-12 18:37:12

bullseyeinteractive
New Member
From: Washington, DC
Registered: 2008-03-11
Posts: 5
Website

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

#32 2008-03-12 19:15:12

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#33 2008-03-12 20:00:30

bullseyeinteractive
New Member
From: Washington, DC
Registered: 2008-03-11
Posts: 5
Website

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

#34 2008-03-12 21:27:12

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#35 2008-03-13 18:51:59

bullseyeinteractive
New Member
From: Washington, DC
Registered: 2008-03-11
Posts: 5
Website

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

#36 2008-03-14 23:45:48

aswihart
Member
From: Pittsburgh, PA
Registered: 2006-07-22
Posts: 345
Website

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

#37 2008-03-15 00:56:53

aswihart
Member
From: Pittsburgh, PA
Registered: 2006-07-22
Posts: 345
Website

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

#38 2008-03-15 06:57:29

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#39 2008-03-15 07:06:01

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [archived] sab_substr

ruud wrote:

I’m seriously considering writing a substring plugin that can deal with XHTML properly.

Awesome news. Is it going to a brand new shiny bling bling plugin or update to this? :P

Last edited by Gocom (2008-03-15 07:06:19)

Offline

#40 2008-03-15 07:23:11

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [archived] sab_substr

Probably brand new.

Offline

#41 2008-03-18 16:31:46

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

  1. Index
  2. » Archives
  3. » [archived] sab_substr

Board footer

Powered by FluxBB