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

php字符串去掉中文

PHP中文网
PHP中文网Original
2016-05-23 16:40:461546browse

php字符串去掉中文

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

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

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);
} 
*/

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

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