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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:49:44+00:00 2026-05-28T06:49:44+00:00

I migrated a News database into a CakePHP news site I am creating. I

  • 0

I migrated a News database into a CakePHP news site I am creating. I have a problem with displaying the text from those migrated news because in the text that was imported to DB there were HTML tags that controls the text within them.

Could anyone help me find a way to remove these texts without compromising the layout of those same news?

Basically, I would like to accomplish the following:

  1. Create a ONE-Time Use only function that I can include in my ArticlesController
  2. For example the function name would be function fixtext(){...}
  3. When I call this function from lets say http://mydomain.com/articles/fixtext, all the affected rows in the Article.body column would be scanned and fixed.

The section of text I want to remove is font-size: 12pt; line-height: 115%;, which in within the <span>...</span> tag.

I had something in mind like this, but I am not sure how to implement it

function fixtext(){
        $this->autoRender = 'FALSE';

        $articles = $this->Article->find(
            'all',
            array(
                'fields' => array(
                        'Article.body',
                        'Article.id'
                ),
                'recursive' => -1
            )
        );

        foreach($articles as $article){
              // Per Dunhamzzz suggestion
              $text = str_replace('font-size: 12pt; line-height: 115%;', '', $article['Article']['body']);
              $this->Article->id =  $article['Article']['id'];
              $this->Article->saveField('Article.body', $text);
        }

        $this->redirect('/');
}

I am not sure how to approach this, and what is the best way.

  • 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-28T06:49:45+00:00Added an answer on May 28, 2026 at 6:49 am

    Firstly, I would personally create a shell to accomplish this as it is a batch job and (depending on the amount of records involved) you may hit Apache’s request timeout limit. Also, it’s a good (fun) learning experience and the shell can be extended to perform future maintenance tasks.

    Secondly, it is a bad idea to parse HTML using (greedy) regular expressions due to the fact it may be malformed. It is safer to use an HTML parser or using simple string replacements instead but, if it is a small regular string that can be pattern matched safely (ie. your not trying to remove the closing </span> tags), regular expressions can work.

    Something like this (untested):

    // app/vendors/shells/article.php
    <?php
    /**
     * Maintenance tasks for Articles
     */
    class Article extends Shell {
    /**
     * Clean HTML in articles.
     */
        public function cleanHtml(){
            // safety kill switch (comment before running)
            $this->quit('Backup the `articles` table before running this!');
            // this query will time out if you have millions of records
            $articles = $this->Article->find('all', array(
                'fields' => array(
                    'Article.name',
                    'Article.body',
                    'Article.id'
                ),
                'recursive' => -1,
            ));
            // loop and do stuff
            foreach ($articles as $article) {
                $this->out('Processing ' . $article['Article']['name'] . ' ... ');
                $article['Article']['body'] = $this->_removeInlineStyles($article['Article']['body']);
                $this->Article->id = $article['Article']['id'];
                $saved = $this->Article->saveField('body', $article['Article']['body']);
                $status = ($saved) ? 'done' : 'fail';
                $this->out($status);
            }
        }
    /**
     * Removes inline CSS styles added by naughty WYSIWYG editors (or pasting from Word!)
     */
        protected function _removeInlineStyles($html) {
            $html = preg_replace('/ style="[^"']+"/gi', '', $html);
            return $html;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have just 'migrated' an SQL Server 2005 database from DEVEL into TEST. Somehow
I've migrated my database on my mobile device away from VistaDB because it's just
I migrated from Windows, and have heard that Linux programmers do not use IDEs
I've migrated the content of a site from one domain to another. I have
We have recently migrated a large, high demand web application to Tomcat 5.5 from
Recently I've migrated from Wicket 1.4 to Wicket 1.5. I've got problem Panel with
I migrated a database from access 2003 to access 2007. It seems to work
I recently migrated my web services from Axis to CXF (2.1). It appears that
We have recently migrated to Git from SVN. We have setup a bare repository
I migrated an SVN server today and ran into an issue. I have a

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.