Guest Posted December 28, 2016 Share Posted December 28, 2016 update super set `name` = REPLACE(`name`, ',' , ' ') I have the following code that removes the comma in a MySQL database column & replaces it with a blank. In the above example, the database is named super & the column is named name. This code works great but currently I'm running the script each day & changing it to also remove periods, question marks, etc. Is there a way I can edit the above code that will not only find & replace the , with a blank space, but edit it so it will find the periods, commas, question mark, exclamation mark, etc all in one run? Please help as I am currently editing the above code to numerous other things to find & replace daily. Thank Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/ Share on other sites More sharing options...
Jacques1 Posted December 28, 2016 Share Posted December 28, 2016 Why on earth do you keep storing punctuation marks only to replace them daily? Why are those characters even a problem? And if they are, why do you not reject or replace them immediately when you receive the input? Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/#findComment-1540791 Share on other sites More sharing options...
Guest Posted December 28, 2016 Share Posted December 28, 2016 Short answer is I DO NOT know how to limit the input of those characters in the code as well as I DO NOT want to know as I am not a programmer nor want to be or pretend to be one. I do work in IT in a totally different realm. The only reason I have been task to do this, is because I have time to do it. With that said, I hope I answered your questions, in hoping someone else will respond instead of getting the third degree with more questions as to how or why I do what I do!! Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/#findComment-1540792 Share on other sites More sharing options...
NotionCommotion Posted December 28, 2016 Share Posted December 28, 2016 If you wish to use SQL to make these modifications and not use any PHP, you should have asked this question in the MySQL (or whichever) forum. I expect you can do so using http://dev.mysql.com/doc/refman/5.7/en/regexp.html. Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/#findComment-1540794 Share on other sites More sharing options...
ginerjm Posted December 28, 2016 Share Posted December 28, 2016 The smarter way would be to write a PHP function that does your editing to an argument that is passed to it. Then you could use that "corrected" variable in your update query. The beauty is that the function can be used prior to any query statement you write instead of having to modify every query statement when you decide to remove something new! Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/#findComment-1540795 Share on other sites More sharing options...
requinix Posted December 28, 2016 Share Posted December 28, 2016 This is not acceptable behavior. Thread pruned. Link to comment https://forums.phpfreaks.com/topic/302823-code-hepl-needed-to-find-replace-characters/#findComment-1540808 Share on other sites More sharing options...
Recommended Posts