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

藏色散人
Release: 2023-03-03 14:04:02
Original
2278 people have browsed it

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;
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!