PHP-将MS Word特殊字符(^ l,^ p,^ s)更改为“,". [英] PHP - Change MS Word special characters (^l , ^p , ^s) to ","

查看:320
本文介绍了PHP-将MS Word特殊字符(^ l,^ p,^ s)更改为“,".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我所拥有的是一个MS Word docx文件,其中包含一些不是很好排序的数据.

So what I have is a MS Word docx file that contains some data which is not really sorted really nice.

/示例输出

1. 姓氏,名字

地址,城市,州邮政编码

Address, City, State Zip

通过执行Ctrl + Shift + *,我可以查看文件中存在的所有特殊字符.

By doing Ctrl+Shift+* I can view all the special characters that exists within the file.

(¶,˚等...)

然后将其替换为,"以用作分隔符,然后以excel格式导出文件.

then replace them with a "," to act as a separator then export the file on an excel format.

是否可以使用PHP替换此符号?

Would there be a way to replace this symbols using PHP?

推荐答案

这个问题在这里已经被困扰了很多..之所以做出回应,是因为您的想法有点曲折.

This issue has been flogged many times here .. am only responding because yours have a little twist.

您需要做的是删除所有不需要的字符,然后用,"替换所有空格"

What you need to do is remove all the characters you don't want , then replace all spaces " " with ","

不删除任何ASII字符(3个示例)

Removing none ASII Characters (3 Examples)

$string = preg_replace('/[^(\x20-\x7F)]*/','', $string);
$string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string);
$string = preg_replace( '/[^[:print:]]/', '',$string);

删除UTF8字符

$string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/u', '', $string);

删除换行符,回车符和制表符

Removing Line Feeds , Carriage Returns and Tabs

$string = preg_replace('/[\x00-\x1F\x80-\xFF]/u', '', $string);

用,"替换";

$string = str_replace(" ",",",$string);
$string = trim($string,",");

您现在有更多的选择..

You have more than enough options now ..

我希望这对您有帮助

谢谢 :)

这篇关于PHP-将MS Word特殊字符(^ l,^ p,^ s)更改为“,".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆