Home > php教程 > PHP源码 > php字符串去掉中文

php字符串去掉中文

PHP中文网
Release: 2016-05-23 16:40:46
Original
1586 people have browsed it

php字符串去掉中文

windows项目迁移到linux中。有很多文件名字是中文。写个脚本批量改名。

$a = "<a>河蟹社会afeowahgieawhjozf候蛇fawgwea维稳aghoiawghowi我日</a>"; 
$result = preg_replace(&#39;/([\x80-\xff]*)/i&#39;,&#39;&#39;,$a); 
var_dump($result);               		
Copy after login

2. [代码][PHP]代码

<?php
try
{
    $hostname = "localhost";
    $dbname = "xxxx";
    $username = "root";
    $pw = "xxxx";
    $pdo = new PDO ("mysql:host=$hostname;dbname=$dbname", "$username", "$pw");
    $db->query("set names utf-8");
} 
catch (PDOException $e)
{
    echo "Failed to get DB handle: " . $e -> getMessage() . "\n";
    exit;
} 
$query = $pdo -> prepare("select id,store_image FROM store");
$query -> execute();

for($i = 0; $row = $query -> fetch(); $i++)
{
    $new_file = preg_replace(&#39;/([\x80-\xff]*)/i&#39;, &#39;&#39;,$row[&#39;store_image&#39;]);
    $id=$row[&#39;id&#39;];
    $sql="update store set store_image=&#39;$new_file&#39; where id=$id";
    $pdo->exec($sql);    
} 

/*
$it = new RecursiveDirectoryIterator("./avatar");
foreach(new RecursiveIteratorIterator($it) as $file)
{
    echo $file . "\n";
    $new_file = preg_replace(&#39;/([\x80-\xff]*)/i&#39;, &#39;&#39;, $file);
    rename($file, $new_file);
} 
*/
Copy after login

 以上就是php字符串去掉中文的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template