[英]How to remove "" and white spaces from this string
我返回了一個字符串變量,如下所示:
"""
65,000
"""
如您所見,值的開頭和結尾都有一些"""
和一些white spaces
。
所以現在我想知道如何刪除所有這些"
雙引號和空格,所以只剩下65,000
?
使用trim()
函數:
$response = '"""
65,000
"""';
$clean_response = trim($response, '" \n\t\r');
您也可以使用preg_replace()
$clean_response = preg_replace('^"+\s*|\s*"+$', '', $response);
這也更具體一點,因為它只替換開頭和結尾的引號,不會替換初始空格之后的引號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.