douxun2023 2013-10-17 12:04
浏览 5
已采纳

从字符串叶子中删除撇号39

I'm trying to remove special characters from a string, preparing it for use in a URL. This is my code as of now:

public function __construct($string) {

    $remove = array("!", "'", '"', "(", ")", ";", "@", "&", "=", "$", ",", "/", "?", "%", "#", "[", "]");

    var_dump($string);
    $this->string = $string;
    $this->string = str_replace($remove, "", $this->string);
    //$this->string = preg_replace("/[\s_\-:+]+/", "-", strtolower($this->string));
    var_dump($this->string);

}

And this is what it outputs:

string(16) "Today's Quiz" string(13) "Today39s Quiz"

That makes no sense... At no point do I convert special characters or anything, so where does the 39 come from? I can't track it down.

  • 写回答

1条回答 默认 最新

  • douqixia7942 2013-10-17 12:07
    关注

    As shown by the length of the string, your input is actually:

    Today's Quiz
    1234567890123456 -> 16 characters
    

    Since you're trimming out & # and ; characters, the result is the remaining 39.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)