PHP 函數拆分

來源:互聯網
上載者:User
$str = "0791280266601-5011";
print_r (explode("-",$str));

顯示效果:Array ( [0] => 0791280266601 [1] => 5011 ) ;


=========================================
第一我要【0】的怎麼拿到?
第二【1】怎麼拿到? 現在是拆分開了,但是不知道怎麼拿到?
大蝦 求指點


回複討論(解決方案)

$t = explode("-",$str);
echo $t[0];
echo $t[1];

$t = explode("-",$str);
echo $t[0];
echo $t[1];

------------------------------
你那是直接去掉橫杠了,我是想去橫杠前面的 以及後面的數字


你那輸出的效果:07912802666015011 錯了

我要的效果是:0791280266601
後面獲到的:5011

版主大人的回複不就可以達到你想要的麼,有撒問題?

版主大人的回複不就可以達到你想要的麼,有撒問題?
--------------------------------------
我現在 做到的是:
$str = "0791280266601-5011";
print_r (explode("-",$str));

顯示效果:Array ( [0] => 0791280266601 [1] => 5011 ) ;

我只想擷取Array ( [0] => 0791280266601 [1] => 5011 ) ;裡面的[0]值

$str = "0791280266601-5011";
$t = explode("-",$str);
echo $t[0]."
";
echo $t[1];

輸出
0791280266601
5011

$str = "0791280266601-5011";
$t = explode("-",$str);
echo $t[0]."
";
echo $t[1];

輸出
0791280266601
5011

謝謝大家,我比較笨 謝謝 可以了。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.