How can I replace characters with preg_replace, that are enclosed in quotes?
I need to replace all special characters, that are in href="" things. Example:
<a href="ööbik">ööbik</a> should become <a href="oobik">ööbik</a>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To replace the “special chars”, you need to use iconv:
$str = iconv('UTF-8', 'ASCII//TRANSLIT', $str);As for getting the values in between the quotes, see the other answers. Use
preg_replace_callbackto execute the conversion above on the matches.EDIT: spoon-feeding everything together:
This example assumes PHP 5.3. Use “create_function” or a named function if you are stuck on PHP 5.2 or below.