Remove quotes from start and end of string in PHP

前端 未结 8 1854
醉酒成梦
醉酒成梦 2020-12-29 01:34

I have strings like these:

\"my value1\" => my value1
\"my Value2\" => my Value2
myvalue3 => myvalue3 
         


        
8条回答
  •  暖寄归人
    2020-12-29 02:07

    How about regex

    //$singleQuotedString="'Hello this 'someword' and \"somewrod\" stas's SO";
    //$singleQuotedString="Hello this 'someword' and \"somewrod\" stas's SO'";
    $singleQuotedString="'Hello this 'someword' and \"somewrod\" stas's SO'";
    
    $quotesFreeString=preg_replace('/^\'?(.*?(?=\'?$))\'?$/','$1' ,$singleQuotedString);
    

    Output

    Hello this 'someword' and "somewrod" stas's SO   
    

提交回复
热议问题