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

php字符串去掉中文

PHP中文网
PHP中文网原创
2016-05-23 16:40:461545浏览

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)!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn