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

  • Home
  • SEARCH
  • 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 7010565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:00:29+00:00 2026-05-27T22:00:29+00:00

I need to truncate string and rewrite it back to array I have got

  • 0

I need to truncate string and rewrite it back to array

I have got a function where I get data from data base

 $data['about_text_list'] = $this->about_text_model->get_array();

I get these fields from data base : id, num, header, text, language

I need to strip_tags and truncate text with function word_limiter

        foreach ($data['about_text_list'] as $items)
        {
            $data['about_text_list']['text'] = word_limiter($items['text'], 100);

            $data['about_text_list']['text'] = strip_tags($items['text']);
        }

in view I do foreach

<? foreach ($about_text_list as $line) : ?>

    <td><?=$line['text']?></td>

<? endforeach; ?>

But I get error, please tell me how to do correct things like this…

  • 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-27T22:00:30+00:00Added an answer on May 27, 2026 at 10:00 pm

    In the loop in your controller, you’re limiting the word count, then setting that to the value in the array. Then, you’re overwriting that value with the strip_tags function. You’re using both functions on the same value instead of using the altered values. (And I would strip the tags first, then limit the word count.)

    You’re also just overwriting the $data['about_text_list']['text'] value each iteration. I’m assuming this needs to be an array of ‘text’ values? I would create a new array with the updated content and merge your $data['about_text_list'] array with the new array.

    Change that loop to this:

    $newarray = array();
    foreach ($data['about_text_list'] as $key => $value)
    {
        $item_text = $value['text'];
        $altered = strip_tags($item_text);
        $newarray[$key]['text'] = word_limiter($altered, 100);
    }
    $data['about_text_list'] = array_merge($data['about_text_list'], $newarray);
    
    // here, you create a new empty array,
    // then loop through the array getting key and value of each item
    // then cache the 'text' value in a variable
    // then strip the tags from the text key in that item
    // then create a new array that mirrors the original array and set 
    //   that to the limited word count
    // then, after the loop is finished, merge the original and altered arrays
    //   the altered array values will override the original values
    

    Also, I’m not sure what your error is (as you haven’t told us), but make sure you’re loading the text helper to give you access to the word_limiter function:

    $this->load->helper('text');
    

    Of course, this all depends on the structure of your array, which I’m guessing at right now.

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

Sidebar

Related Questions

Does anybody have an example of spliting a html string (coming from a tiny
I have an apparently simple regex query for pipes - I need to truncate
I have a string that looks like this: 0.4794255386042030002732879352156 which is approximately the sin(0.5).
On an ASP.NET GridView, I have a field that prints a string from the
I've got a situation where I need to have my LINQ to Entities query
string sqlQuery = unknown; I need to write a function which receives a sql
my application takes in a string like this 2002-10-15 10:55:01.000000. I need to validate
In my Rails (2.3, Ruby 1.8.7) application, I need to truncate a string to
Need a function that takes a character as a parameter and returns true if
need ask you about some help. I have web app running in Net 2.0.

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.