Search code examples
phpjavascriptjqueryexpanderellipsis

how can show 100 character and hide more for expander?


I have a dynamic site with MySQL database and I want to create "see more" button just like on Facebook, and I should probably use jQuery expander, but I have a big problem. I don't know how can I hide more characters...

Bellow is my code:

if ( $message = mb_strlen(htmlspecialchars($this->post_message) ) > 200 ); {
    $message = str_cut(htmlspecialchars($this->post_message),100);
    echo $message.'<span style="float:left;clear:both"> <a href="" target="_blank" title="more" style="font-size:9px;" >more</a></span>';
}

who can handle complete code for this ? This code just cuts more characters, but I want to hide them and show in expander!

Sorry for my bad language, I don't speak English well :)


Solution

  • You have an error in your syntax.

    if ( $message   =  mb_strlen(htmlspecialchars($this->post_message) ) > 200 ); {
    

    Should be

    if ( $message   =  mb_strlen(htmlspecialchars($this->post_message) ) > 200 ) {
    

    There should be no ; after your if statement

    str_cut is not a PHP function. What you are looking for is substr.

    In your case, you would use it like this:

    $message = substr(htmlspecialchars($this->post_message),0,100);