【问题标题】:php substr delete?php substr 删除?
【发布时间】:2010-12-05 10:09:11
【问题描述】:

我的数据库中有一个游戏 ip,如下所示:"271.29.248.23:27912"

我希望子字符串采用最后 5 个数字“27912”,并且我想删除 ":"。 这可能吗?有人可以帮助我吗?

如果可能的话,我希望数字是这样的,这样会更容易......

$ip = "271.29.248.23";
$port = "27912";

请帮帮我,我需要这个作为脚本:(

【问题讨论】:

    标签: php string numbers substring substr


    【解决方案1】:
     list($ip, $port) = explode(":", "$your_string:");
    

    【讨论】:

    • 感谢您的快速回复,我会测试一下:)
    • $your_string . ':' 会更干净。
    【解决方案2】:

    您也可以使用parse_url,它将处理更多案例:

    $url = "271.29.248.23:27912";
    print_r(parse_url($url));
    

    打印:

    Array
    (
        [host] => 271.29.248.23
        [port] => 27912
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-07
      相关资源
      最近更新 更多