我有一個漂亮的url鏈接: www.abcd.com/Topic-V-CNHVNTNCHUUINP-Gangulys-waving-jersey-at-Lords-or-Dhonis-six-to-win-the-world-cup-- - 這是印度板球歷史上最大的贏球時刻 - Sourav-Ganguly-Mahendra-Singh-Dhoni如何獲取第一個「 - 」和第三個「 - 」之間的所有內容?
我只想抓取「V-CNHVNTNCHUUINP」。我寫的代碼不起作用:
$value = "www.abcd.com/Topic-V-CNHVNTNCHUUINP-Gangulys-waving-jersey-at-Lords-or-Dhonis-six-to-win-the-world-cup---Which-was-the-biggest-winning-moment-in-Indian-cricket-history-Sourav-Ganguly-Mahendra-Singh-Dhoni";
$newstr = substr($value, 0, strpos($value, '-', strpos($value, '-')+3));
$afterunderscore = substr($newstr, strpos($newstr, "-") + 1);
這是取我:V-CNHVNTNCHUUINP。
但隨着鏈路進行測試時: www.abcd.com/Topic-HN-CNHVNTNCHWTSSW-Sharukh-Khan-or-Salman-Khan---Who-is-the-biggest-superstar-of-bollywood
我得到的結果是:HN。
目標:取HN-CNHVNTNCHWTSSW當鏈接www.abcd.com/Topic-HN-CNHVNTNCHWTSSW-Sharukh-Khan-or-Salman-Khan---Who-is-the-biggest-巨星 - 寶萊塢的-