Field method to remove special characters?

Hi all

Is there a field method which will remove characters like “” from a returned value?

I am trying to update a page description based on the text within the page. This is the code I’m using.

$page->text()->toBlocks()->filterBy('type', 'text')->excerpt(150)

The issue happens when the text is for example

"this is sample text" said someone

and then the description tag looks like

content=""this is sample text" said someone" 

What I would like to do is, remove the extra “” and have the content=“this is sample text said someone”

Does that even cause issues for the code? I just looked at the code and it didn’t seem right…

there is no in-build fieldmethod for that. you can eihter define your own and do the replacement or wrap your call directly into a str_replace call.

1 Like

Thanks mate.

Following instructions on that link I’ve done the following and it removes the quotes.

  $article_title = preg_replace('/[\'"`“”‘’]/u', '', $page->title());
  $article_description = $page->text()->toBlocks()->filterBy('type', 'text')->excerpt(150);
  $article_description = preg_replace('/[\'"`“”‘’]/u', '', $article_description);