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:
<?php header('content-type:text/html;charset=utf-8'); $param = '{"id":"12", "name":"hi"}'; echo "原字符串:".$param."<br>"; $new = preg_replace('/\"/', "'", $param); echo "新字符串:".$new; ?>
Method 2: Using str_replace() Function
str_replace() function replaces some characters in a string.
Example:
<?php header('content-type:text/html;charset=utf-8'); $param = '{"id":"12", "name":"hi","ang":"23"}'; echo "原字符串:".$param."<br>"; $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!

方法:1、用str_replace(),语法“str_replace(" "," ",$str)”;2、用preg_replace()配合正则表达式,语法“preg_replace('/\s+/'," ",$str)”。

两种去除方法:1、使用rtrim()函数,语法“rtrim(数值,"0")”,可去除数值后面连续的零。2、用substr_replace(),语法“substr_replace(数值,'', -位置值)”,可从指定位置开始将零替换为空字符。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php将小数点转为百分比的方法:1、利用“*”运算符将小数乘以100,语法“小数 * 100”,可将小数转为百分值;2、使用字符串拼接符“.”将百分值和“%”符拼接在一起,形成百分比字符串即可,语法“百分值."%"”。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

转换方法:1、使用“array_merge_recursive(数组1,数组2,数组3...)”语句将多个数组合并为一个数组;2、使用json_encode()将合并后的数组转为json数据,语法“json_encode(合并后的数组)”。

两种方法:1、用“substr_replace($str,"",strpos($str,"指定字符")+1)”语句,将指定字符位置后的内容替换为空字符;2、用“substr($str,0,strpos($str,"指定字符")+1)”语句。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)
