This is my string:
这是我的字符串:
$a='"some text';
How can I remove the double quote so my output will look like this?
如何删除双引号,以便我的输出看起来像这样?
some text
6 个解决方案
#2
6
if string is: $str = '"World"';
如果字符串是:$ str ='“World”';
ltrim()
function will remove only first Double quote.
ltrim()函数只会删除第一个双引号。
Output: World"
So instead of using both these function you should use trim()
. Example:
因此,您应该使用trim()而不是同时使用这两个函数。例:
$str = '"World"';
echo trim($str, '"');
Output-
World
#3
4
Probably makes the most sense to use ltrim()
since str_replace()
will remove all the inner quote characters (depends, maybe that's what you want to happen).
可能最有意义的是使用ltrim(),因为str_replace()将删除所有内部引号字符(取决于,也许这就是你想要发生的事情)。
ltrim
— Strip whitespace (or other characters) from the beginning of a stringltrim - 从字符串的开头删除空格(或其他字符)
echo ltrim($string, '"');
If you want to remove quotes from both sides, just use regular trim()
, the second argument is a string that contains all the characters you want to trim.
如果要从双方删除引号,只需使用常规trim(),第二个参数是一个包含要修剪的所有字符的字符串。
#5
0
There are different functions are available for replacing characters from string below are some example
一些例子中有不同的功能可用于从字符串中替换字符
$a='"some text';
echo 'String Replace Function<br>';
echo 'O/P : ';
echo $rs =str_replace('"','',$a);
echo '<br>===================<br>';
echo 'Preg Replace Function<br>';
echo 'O/P : ';
echo preg_replace('/"/','',$a);
echo '<br>===================<br>';
echo 'Left Trim Function<br>';
echo 'O/P : ';
echo ltrim($a, '"');
echo '<br>===================';
Here is the O/P
这是O / P.
#6
-2
You can do this:
你可以这样做:
str_replace()
echo str_replace('\"', '', $a);
#1
#2
6
if string is: $str = '"World"';
如果字符串是:$ str ='“World”';
ltrim()
function will remove only first Double quote.
ltrim()函数只会删除第一个双引号。
Output: World"
So instead of using both these function you should use trim()
. Example:
因此,您应该使用trim()而不是同时使用这两个函数。例:
$str = '"World"';
echo trim($str, '"');
Output-
World
#3
4
Probably makes the most sense to use ltrim()
since str_replace()
will remove all the inner quote characters (depends, maybe that's what you want to happen).
可能最有意义的是使用ltrim(),因为str_replace()将删除所有内部引号字符(取决于,也许这就是你想要发生的事情)。
ltrim
— Strip whitespace (or other characters) from the beginning of a stringltrim - 从字符串的开头删除空格(或其他字符)
echo ltrim($string, '"');
If you want to remove quotes from both sides, just use regular trim()
, the second argument is a string that contains all the characters you want to trim.
如果要从双方删除引号,只需使用常规trim(),第二个参数是一个包含要修剪的所有字符的字符串。
#4
#5
0
There are different functions are available for replacing characters from string below are some example
一些例子中有不同的功能可用于从字符串中替换字符
$a='"some text';
echo 'String Replace Function<br>';
echo 'O/P : ';
echo $rs =str_replace('"','',$a);
echo '<br>===================<br>';
echo 'Preg Replace Function<br>';
echo 'O/P : ';
echo preg_replace('/"/','',$a);
echo '<br>===================<br>';
echo 'Left Trim Function<br>';
echo 'O/P : ';
echo ltrim($a, '"');
echo '<br>===================';
Here is the O/P
这是O / P.
#6
-2
You can do this:
你可以这样做:
str_replace()
echo str_replace('\"', '', $a);