How do I replace double quotes with single quotes

后端 未结 8 752
一向
一向 2020-11-30 08:19

How can I replace \"\" (I think it\'s called double quotes) with \'\' (I think its called single quotes) using PHP?

相关标签:
8条回答
  • 2020-11-30 08:56

    You can use str_replace, try to use http://php.net/manual/en/function.str-replace.php it contains allot of php documentation.

    <?php
    
    echo str_replace("\"","'","\"\"\"\"\" hello world\n");
    ?>
    
    0 讨论(0)
  • 2020-11-30 09:03

    Try this

    //single qoutes
    $content = str_replace("\'", "'", $content); 
    
    //double qoutes
    $content = str_replace('\"', '"', $content); 
    
    0 讨论(0)
  • 2020-11-30 09:08

    Try with preg_replace,

    <?php
    $string="hello \" sdfsd \" dgf";
    echo $string,"\n";
    echo preg_replace("/\"/","'",$string);
    ?>
    
    0 讨论(0)
  • 2020-11-30 09:11

    I like to use an intermediate variable:

    $OutText = str_replace('"',"'",$InText);
    

    Also, you should have a Test.php file where you can try stuff out:

    $QText = 'I "am" quoted';
    echo "<P>QText is: $QText";
    $UnQText = str_replace ('"', '', $QText);
    echo "<P>Unquoted is: $UnQText";
    

    z

    0 讨论(0)
  • 2020-11-30 09:13
    str_replace('"', "'", $text);
    

    or Re-assign it

    $text = str_replace('"', "'", $text);
    
    0 讨论(0)
  • 2020-11-30 09:14

    Use

    $str = str_replace('"','\'',$str)
    
    0 讨论(0)
提交回复
热议问题