I’m trimming a string in an excerpt as follows:

$mod_trim_to = strpos(get_the_excerpt(), ' ', 115);
$trimmed_exceprt = substr(get_the_excerpt(),0,$mod_trim_to);

The goal here is to trim the excerpt to 115 characters in cases where it’s being auto-generated and breaking the bounds of a very small space, as specified by the third party graphic designer.

The function returns properly, but also throws a warning:

PHP Warning:  strpos(): Offset not contained in string

I can only guess that strpos() doesn’t like searching for a space? What is the correct way to write this so I don’t end up with an error log?

Thanks

Read more here: Why is this strpos() returning an error?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: