edou Posted February 6, 2013 Share Posted February 6, 2013 Hi, I'm trying to make a website using wordpress and would like to find a way to count the amount of caracters used in a message in order to stop displaying at a certain point with a link like 'read more', linking to the specific page of this message. Can anyone help. It's probably basic, but I'm really new with php. Thanks. E Quote Link to comment https://forums.phpfreaks.com/topic/274124-count-caracters/ Share on other sites More sharing options...
Jessica Posted February 6, 2013 Share Posted February 6, 2013 For characters use substr. For words, a regular expression. Quote Link to comment https://forums.phpfreaks.com/topic/274124-count-caracters/#findComment-1410527 Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 Slight expansion upon Jessica's post: If you use UTF-8 on your site, you want to use mb_substr () instead of plain substr (). To properly support those multi-byte characters. Quote Link to comment https://forums.phpfreaks.com/topic/274124-count-caracters/#findComment-1410550 Share on other sites More sharing options...
edou Posted February 7, 2013 Author Share Posted February 7, 2013 could you be more specific. I really know nothing about php. I think the function that's now counting the following is: if ( count($content) > 1 ) { if ( $more ) { $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; } else { if ( ! empty($more_link_text) ) $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); $output = force_balance_tags($output); } } The problem with that, is that if I place pictures after my text, it won't display it unless I click 'read more'. So I'm obliged to place first my pictures, which is not so nice to see. Quote Link to comment https://forums.phpfreaks.com/topic/274124-count-caracters/#findComment-1410700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.