Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在php中字符串的0和最后一个索引处可用,如何删除卷曲引号?_Php_Drupal 8 - Fatal编程技术网

如果在php中字符串的0和最后一个索引处可用,如何删除卷曲引号?

如果在php中字符串的0和最后一个索引处可用,如何删除卷曲引号?,php,drupal-8,Php,Drupal 8,如果在php中字符串的0和最后一个索引处可用,如何删除$checkChar值 条件不适用于卷引号 我正在尝试这个 $checkArr = ['"', '“', '”']; $str['quote'] = "“This is a sample text.”"; foreach ($checkArr as $key){ if($str['quote'][0] === $key || $str['quote'][strlen($str['quote']) - 1] === $key {

如果在php中字符串的0和最后一个索引处可用,如何删除$checkChar值

条件不适用于卷引号

我正在尝试这个

$checkArr = ['"', '“', '”'];
$str['quote'] = "“This is a sample text.”";

foreach ($checkArr as $key){
  if($str['quote'][0] === $key || $str['quote'][strlen($str['quote']) - 1] === $key {
    $str['quote'] = str_replace($key, '', $str['quote']);
  }
}



您可以使用删除字符串外部的引号:

$checkArr = ['"', '“', '”'];
$str['quote'] = "“This is a sample text.”";

echo trim($str['quote'], implode('', $checkArr));
输出:

This is a sample text.
This is a sample text.
注意

如果字符串外部有多个引号,它们都将被删除,例如

$checkArr = ['"', '“', '”'];
$str['quote'] = "““This is a sample text.””";

echo trim($str['quote'], implode('', $checkArr));
输出:

This is a sample text.
This is a sample text.
您可以使用删除字符串外部的引号:

$checkArr = ['"', '“', '”'];
$str['quote'] = "“This is a sample text.”";

echo trim($str['quote'], implode('', $checkArr));
输出:

This is a sample text.
This is a sample text.
注意

如果字符串外部有多个引号,它们都将被删除,例如

$checkArr = ['"', '“', '”'];
$str['quote'] = "““This is a sample text.””";

echo trim($str['quote'], implode('', $checkArr));
输出:

This is a sample text.
This is a sample text.

ltrim
rtrim
是否合适?
ltrim
rtrim
是否合适?