String Find and Replace in MySQL

When creating resource links to assets in our CMS a couple of users had inadvertently linked to the ‘._Filename.doc’ file created by OSX, instead of the intended ‘Filename.doc – on just under 300 files.

Running a quick query to return all the affected resources I used the REPLACE funtion in MYSQL to set all the asset values again (minus the ‘._’)

update TABLENAME
set value = REPLACE(value, '/._', '/')
where value like '%/._%'

Continue reading “String Find and Replace in MySQL”

Replacing accented character with it’s standard character in PHP

When writing a function to save audio files with a user friendly filename , as well as a regex to remove any unwanted spaces and punctuation, I needed to replace any accented characters with their standard format.

e.g If I was saving a Beyoncé album I needed the ‘é’ in her name to be replaced with an ‘e’.

The following works perfectly:

iconv("utf-8","ascii//TRANSLIT",$filename);