im getting this warning on my website "Warning: count(): Parameter must be an array or an object that implements Countable in /home4/geec/public_html/home/wp-content/plugins/industing-assistance/inc/elementor/style/services/style1.php on line 92
here is my line 92
echo substr($content, 0, ($spos = strpos($content, ' ', $lcount = count($content) > 65 ? $lcount : 65)) ? $spos : $lcount );
What exactly do I need to add or change on my php file?
Thanks
My Answer:
The warning is indicating that the variable $content is not an array or an object that implements Countable, so you cannot use the count() function on it.
To fix this issue, you can check if $content is an array or an object before using the count() function. Here is an example of how you can modify your code:
php
if(is_array($content) || is_object($content)) {
echo substr($content, 0, ($spos = strpos($content, ' ', $lcount = count($content) > 65 ? $lcount : 65)) ? $spos : $lcount );
} else {
// handle the case where $content is not an array or object
echo "Content is not an array or object";
}
By adding this check, you can prevent the warning from occurring when $content is not an array or object.
Rate this post
5 of 5 based on 2891 votesComments