首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP如何转换或删除字符串中的特殊字符?

PHP如何转换或删除字符串中的特殊字符?
EN

Stack Overflow用户
提问于 2019-07-04 17:30:47
回答 4查看 96关注 0票数 0

我想要将任何特殊字符转换为它的原始值,我正在尝试这个函数,但它不起作用。这是我的代码。

代码语言:javascript
复制
  $text = "Tuscaloosa County – Hunting and Timber Invest";

  echo $html = mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8");
EN

回答 4

Stack Overflow用户

发布于 2019-07-04 17:57:41

我不知道这是不是你想要的,但试一试

$text = "Tuscaloosa County – Hunting and Timber Invest"; echo $html =mb_convert_encoding($text, 'UTF-8');

票数 0
EN

Stack Overflow用户

发布于 2019-07-04 18:13:34

尝试此清理函数

代码语言:javascript
复制
function clean($string) {
       $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

       return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
    }
     $text = "Tuscaloosa County – Hunting and Timber Invest";

      echo $html = clean($text);
票数 0
EN

Stack Overflow用户

发布于 2019-07-04 18:13:48

1。尝试使用next:

代码语言:javascript
复制
 $text = "Tuscaloosa County – Hunting and Timber Invest";
$html_1 = utf8_encode($text);
$html_2 = iconv('ISO-8859-1', 'UTF-8', $text);
$html_2 = mb_convert_encoding($text, 'UTF-8', 'ISO-8859-1');

代码语言:javascript
复制
 $text = "Tuscaloosa County – Hunting and Timber Invest";
$html_1 = utf8_decode($text);
$html_2 = iconv('UTF-8', 'ISO-8859-1', $text);
$html_2 = mb_convert_encoding($text, 'ISO-8859-1', 'UTF-8');

2。这样的话:

代码语言:javascript
复制
$html= mb_convert_encode($text,'HTML-ENTITIES','UTF-8'); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56884856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档