How to remove quotes from a string in php?

Member

by armani , in category: PHP , 2 years ago

How to remove quotes from a string in php?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@armani You can use str_replace() function to remove all quotes from any string in PHP, here is code as example:


1
2
3
4
5
6
<?php

$str = "test\" 'string";

// Output: test string
echo str_replace(['"', "'"], "", $str);


by yadira.tillman , a year ago

@armani 

In PHP, you can remove quotes from a string using the stripslashes() function. This function removes any backslashes that were used to escape quotes in the string. Here's an example:

1
2
3
$string_with_quotes = "This is a "quoted" string.";
$string_without_quotes = stripslashes($string_with_quotes);
echo $string_without_quotes;


Output:

1
This is a "quoted" string.


Note that this function only removes backslashes that were used to escape quotes. If the string contains actual quote characters that you want to remove, you can use the str_replace() function to replace them with an empty string. Here's an example:

1
2
3
$string_with_quotes = "This is a "quoted" string.";
$string_without_quotes = str_replace('"', '', $string_with_quotes);
echo $string_without_quotes;


Output:

1
This is a quoted string.