Skip to content

Instantly share code, notes, and snippets.

@aschanMarcus
Created March 19, 2014 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aschanMarcus/9639539 to your computer and use it in GitHub Desktop.
Save aschanMarcus/9639539 to your computer and use it in GitHub Desktop.
Remove inline CSS from body fields in Drupal.
/**
* For removing inline CSS from body fields in Drupal.
*
* -Install devel module.
* -Navigate to devel/php.
* -Paste the following code and execute.
*/
$results = db_select('field_data_body', 'f')
->fields('f', array('entity_id', 'body_value'))
->execute()
->fetchAll();
foreach ($results as $result) {
$body = preg_replace('/(<[^>]*) style=("[^"]+"|\'[^\']+\')([^>]*>)/i', '$1$3', $result->body_value);
db_update('field_data_body')
->fields(array(
'body_value' => $body,
))
->condition('entity_id', $result->entity_id)
->execute();
}
@dasginganinja
Copy link

Thanks!

@nerdstein
Copy link

It would be a good idea to update field revisions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment