Replacement method: 1. Use the preg_replace() function with the regular expression "/\"/", the syntax "preg_replace('/\"/',"'", string)"; 2. Use str_replace() function, syntax "str_replace('"',"'",string)".
The operating environment of this tutorial: windows7 system, PHP7. Version 1, DELL G3 computer
php method to replace double quotes with single quotes
Method 1: Use preg_replace() The function works with a regular expression to convert double quotes into single quotes
preg_replace function performs a regular expression search and replace.
The regular expression used is:
/\"/
Example:
"; $new = preg_replace('/\"/', "'", $param); echo "新字符串:".$new; ?>
Method 2: Using str_replace() Function
str_replace() function replaces some characters in a string.
Example:
"; $new = str_replace('"',"'",$param); echo "新字符串:".$new; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to replace double quotes with single quotes in php. For more information, please follow other related articles on the PHP Chinese website!