Home  >  Article  >  Backend Development  >  How to convert English quotation marks to Chinese quotation marks in php

How to convert English quotation marks to Chinese quotation marks in php

藏色散人
藏色散人Original
2020-07-30 09:15:222466browse

php quotation mark conversion method: first create a PHP sample code file; then define a "convertQuotToChinese" method; then use strpos and substr and other functions to convert quotation marks; finally execute the file and output the conversion result. .

How to convert English quotation marks to Chinese quotation marks in php

Recommended: "PHP Video Tutorial"

php Convert English quotation marks into Chinese quotation marks in pairs

$test_string = 'this is a "test as" string juventus vs "napoli" is  b a bing match';
echo convertQuotToChinese($test_string);
 
function convertQuotToChinese($string) {
    $flag = false; //false显示开始的中文引号,true时显示结束的中文引号
    while(false !== ($i = strpos($string, '"'))) {
        $begin_string = substr($string, 0, $i);
        $end_string = substr($string, $i+1-strlen($string));
        $quot = $flag ? '”' : '“';
        $flag = !$flag;
        $string = $begin_string.$quot.$end_string;    
    }
    return $string;
}

The above is the detailed content of How to convert English quotation marks to Chinese quotation marks in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn