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 7788959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:08:38+00:00 2026-06-01T21:08:38+00:00

I found the following PHP script create by webbiedave. // strip tags to avoid

  • 0

I found the following PHP script create by webbiedave.

// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {
    // truncate string
    $stringCut = substr($string, 0, 500);

    // make sure it ends in a word so assassinate doesn't become ass...
    $string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="/this/story">Read More</a>';
}
echo $string;

Now my question is: How can I specify in strrpos() to search for space or dot?

So if I set a maximum string length of 22 and my inout string is:

StackOverFlow is the best site ever

Excluding the appended HTML tag, the output will be:

StackOverFlow is the...

If I have an input of:

http://stackoverflow.com is the best site ever

Excluding the appended HTML tag, the output will unfortunately be

...

How can I modify this script to cut text if it finds a dot in the string so that http://stackoverflow.com is the best site ever becomes http://stackoverflow ... ?

  • 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-06-01T21:08:40+00:00Added an answer on June 1, 2026 at 9:08 pm

    I would check string from end, cause You need to delete words that are incomplete. Condition of that incomplete word is when short string is not ending with space or with a end character such as ‘!’ or just dot. Next cond is to see if +1 sign after end of string is also such character. If it is the You just have to del any character from end to next space. This could be done by regexp (something similiar to /[:alfa]+$/, probadly better would have to be done).

    This is a simple way to do basic things, but a good start I think.

    EXAMPLE of what it could be:

    function word_wrap_custom($string, $limit){
    $oneWord = explode(' ', $string);
    if(count($oneWord) < 2 )
        return $oneWord[0];
    $string = substr($string, 0, $limit + 2);
    
    $endchar =  substr($string, $limit, $limit + 1);
    
    $postendchar = substr($string, $limit + 1, $limit + 2);
    
    $arrAccetpEndChar = array(' ', '!', '?', ',', '.', ';', ':');
    
    if(in_array($postendchar, $arrAccetpEndChar) || in_array($endchar, $arrAccetpEndChar))
    {
        return $string;
    }
    else
    {
        return preg_replace('/[A-Za-z0-9]+$/', '', $string);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found the following code in a PHP script and was wondering why
I'm looking for a PHP-like high level C utility library. I've found the following
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I have the following code in a PHP script: <?php if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
I get the following error: Fatal error: Class 'mysqli' not found in my php
I have found the following script which is apparently written using the javascript framework
I want to do the following. 1) Create a database. 2) Run a script
I'm working on an image upload script with PHP, I found one someone was
I have created this php script, to create an xml-file from my database: <?php
I found a PHP script that parses excel files, but there seems to be

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.