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:
- Create a ONE-Time Use only function that I can include in my
ArticlesController
- For example the function name would be
function fixtext(){...}
- When I call this function from lets say
http://mydomain.com/articles/fixtext
, all the affected rows in theArticle.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.
');`. It is almost the same thing, but it removes every HTML tags I didnt need in that text, except for
– AKKAweb Jan 21 '12 at 00:23and . AWESOME. Thank you very much....