Convert Quotes to Curly Smart Quotes

7 posts by 3 authors in: Forums > CMS Builder
Last Post: March 4, 2021   (RSS)

By JeffC - December 14, 2020

Hi

Is there a way to convert quotes to smart quotes? I have 1500+ products that that been uploaded from a csv file. I would like to change:

' to ‘
' to ’

" to “
" to ”

I tried a find and replace using PHP MyAdmin but it didn't recognise the difference between the characters.

Could this be done using Developer Console?

Thanks

Jeff

Hey Jeff,

I did a google search for your question  IE: Convert Quotes to Curly Smart Quotes php, and came up with lots of suggestions using simple preg_replace commands.

You might want to give that a try and see what you come up with, or look at this one: https://www.neowin.net/forum/topic/1387562-php-convert-straight-quotes-to-smart-quotes/

Good luck,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

I suppose that technically, the answer is yes, but I'm not sure that it will make a difference in  the real world.

Maybe someone has a suggestion for the back end approach

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Jenna - February 1, 2021

Hi Jeff,

Are you still looking for us to chime in on this one? I notice it's from December 2020.

Please let us know if you're still looking for assistance.

Jenna Cooke - PHP Programmer
interactivetools.com

By JeffC - March 3, 2021

Hi Jenna

Thanks for following up, and sorry for the delayed reply. I'm not having much joy actually. Your help would be appreciated.

Jerry's post was helpful, and I think a php approach would be fine. Just not sure how to apply a universal rule to affect all the text on a page.

Thanks

Jeff

By Jenna - March 4, 2021

Hi Jeff,

You should be able to do this with a simple plugin. You would need to utilize the viewer action "viewer_output_rows" seen below in the first line. 

addAction('viewer_output_rows', 'pluginName_convertToSmartQuotes', null, 1);
function pluginName_convertToSmartQuotes($rows, $listDetails, $schema) {
  $fieldsToConvert = array('content', 'title', 'field_1', 'field_2'); // List your fields that you want to convert in this array
  //Check against $schema if the column exists
  $columnsExist = function_to_check_if_keys_exist($fieldsToConvert, $schema);
  if (!$columnsExist ) { return $rows; } // Just return rows if nothing exists
  foreach (array_keys($rows) as $index) {
    $row = &$rows[$index];
    foreach ($columnsExist as $field) {
      if ( isset($row[$field]) && $row[$field] != '' )  { 
        $row[$field] = preg_replace(array('/\b"/','/"/',"/'/"), array('”','“',"’"), $row[$field]); 
      }
    }
    
    unset($row);
  }
  return $rows;
}

I did use some pseudo code to indicate what functionality you'd be looking to create [ function_to_check_if_keys_exist() ]  so you can get the idea of what would need to be done. This pseudo function would need to be written to return an empty array if no columns/keys match or the columns that match.

If you're looking for us to write a quick plugin to help you accomplish this, send us an email at support@interactivetools.com and we would be happy to help you further and it shouldn't take much time at all. 

Let me know if that helps or if you have further questions!

Jenna Cooke - PHP Programmer
interactivetools.com