0

I have a small piece of code that searches a string for a pattern of <quote>text<quote> - The idea here being to find quotes within a string.

Currently I have this as the preg_match function

preg_match_all('/"([^"]+)"/', $essay, $q);

However I have found that when pasting in text from word processors or PDFs - the quotation mark becomes “ ” a rich text format quotation mark.

How could you go about filtering these out and converting them back to plain text quotation marks?

Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
user2075625
  • 93
  • 2
  • 11

1 Answers1

1

You can simply use str_replace() function to convert these smart quotes to normal quotes, like this:

$essay = str_replace(array('“','”'), '"', $essay);
preg_match_all('/"([^"]+)"/', $essay, $q);
Stoic
  • 10,536
  • 6
  • 41
  • 60