Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 711901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:47:17+00:00 2026-05-14T04:47:17+00:00

How can I this PHP function include in jquery .html? PHP function: function trim_text($string,

  • 0

How can I this PHP function include in jquery .html?

PHP function:

function trim_text($string, $limit, $break="<", $pad=" ...")
{
$words = explode(' ', htmlentities(strip_tags($string)));
$countr = count($words);
if ($countr <= 8)
{
return $string;
}else{


// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
$string = substr($string, 0, $limit);
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {

  $string = substr($string, 0, $breakpoint) . $pad;
}
}
$last_space = strrpos(substr($string, 0, $limit), ' ');
$string = substr($string, 0, $last_space);
$string = strip_tags($string);  
return $string.$pad;
}
}

And the Jquery part of code where I want to in “.html” part somehow call this function is:

$(" .text").html('<div>'+ message +'</div>');

What I want to do is trim this “message” text using PHP function. Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:47:17+00:00Added an answer on May 14, 2026 at 4:47 am

    In your JS, send the text to be trimmed to the script which will do the trimming. The server should send back the trimmed string, e.g.:

    var theText = $("#aTextarea").val();
    $.post('trimscript.php', {text: theText}, function(response) {
        $('.text').html('<div>' + response + '</div>');
    });
    

    In your PHP, grab the GET or POST variable, trim it, and send it back:

    <?php
    if(isset($_POST['text']) && !empty($_POST['text'])) {
        $text = trim_text($_POST['text']);
        echo $text;
    }
    ?>
    

    I think that describes the flow of what’s needed. Of course, there are numerous other ways to implement this, the above is merely a simple example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain why this jQuery .html() function is not outputting anything? I'm new
I'm using PHP, HTML & jQuery. Lets say this is my original working index.html
<a class=checkModelButton href=check.php>Check</a> <div id=model_list></div> include jquery and function deleteRow(): jQuery('.checkModelButton').click(function(event){ event.preventDefault(); var url
Can anyone help in this php page navigation script switch on counting normal serial
I have this PHP page where the user can select and un-select items. The
Can anyone help me with reversing this PHP page navigation? Current script setting shows
I'm using this PHP framework for use with Shopify's API Can anyone help me
I can't seem to get the correct Unix epoch time out of this PHP
Possible Duplicate: Dirt-simple PHP templates… can this work without eval ? Let's say I
Dear everybody who can help, I have this PHP > MongoDB problem, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.