Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace double quotes with single quotes

Tags:

regex

php

quotes

How can I replace "" (I think it's called double quotes) with '' (I think its called single quotes) using PHP?

like image 474
streetparade Avatar asked Mar 11 '10 10:03

streetparade


People also ask

How do you replace a double quote in a string?

To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.

How do you type a single quotation mark?

On the keyboard You can make single quotation marks on most computers by pressing the apostrophe/quotation mark key to the left of ENTER. Double quotation marks are made on most computers by holding SHIFT and pressing the apostrophe/quotation mark key to the left of ENTER.

Why use single quotes instead of double quotes?

If you are an American, using quotation marks could hardly be simpler: Use double quotation marks at all times unless quoting something within a quotation, when you use single. It's different in the greater Anglosphere, where they generally use singles in books and doubles in newspapers.


2 Answers

str_replace('"', "'", $text); 

or Re-assign it

$text = str_replace('"', "'", $text); 
like image 99
YOU Avatar answered Oct 09 '22 21:10

YOU


Use

$str = str_replace('"','\'',$str) 
like image 25
codaddict Avatar answered Oct 09 '22 19:10

codaddict