How to replace double quotes with single quotes in php

青灯夜游
Release: 2023-03-15 20:04:01
Original
2894 people have browsed it

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)".

How to replace double quotes with single quotes in php

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; ?>
Copy after login

How to replace double quotes with single quotes in php

Method 2: Using str_replace() Function

str_replace() function replaces some characters in a string.

Example:

"; $new = str_replace('"',"'",$param); echo "新字符串:".$new; ?>
Copy after login

How to replace double quotes with single quotes in php

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!