我想从链接获取ID我已经在数组中设置了所有链接并向前冲击斜线/然后循环它但我在数组中只获得一个id主链接
"/4tzCuIpHHhc/long-title-here",
我需要此ID 4tzCuIpHHhc
我正在尝试这个
<?php
$links = array(
"/WSNINQJZj1s/weightlifting-fairy-kim-bok-ju-ep05-lee-sung-kyung-run-nam-joo-hyuk-errand-20161130",
"/Nmy5FWgX0S0/weightlifting-fairy-kim-bok-ju-ep05-nam-joo-hyuk-reject-a-proposal-20161130",
"/u3gumA7-38A/weightlifting-fairy-kim-bok-ju-ep05-did-you-fall-in-love-with-my-brother-20161130",
"/Zsa_saeRT1E/weightlifting-fairy-kim-bok-ju-ep05-sung-kyung-offered-joo-hyuk-a-deal-20161130",
"/9q0uUfSr0lE/weightlifting-fairy-kim-bok-ju-ep05-nam-joo-hyuks-angry-at-lee-sung-kyung-20161130",
"/UH6YqMDdMDE/weightlifting-fairy-kim-bok-ju-ep05-sung-kyung-and-lee-jae-yoons-drive-date-20161130",
"/5pC2NJtCg_I/weightlifting-fairy-kim-bok-ju-ep03-did-you-fight-because-of-me-20161123",
"/UbxbVugdIdo/weightlifting-fairy-kim-bok-ju-ep01-lee-sung-kyung-fell-into-the-pool-20161116",
"/f29SpSqcOQc/weightlifting-fairy-kim-bok-ju-ep03-lee-sung-kyung-got-into-trouble-20161123",
"/ydWm_Pnp1BQ/weightlifting-fairy-kim-bok-ju-ep04-lee-sung-kyung-vs-nam-joo-hyuk-20161124",
"/uiLlQSexJr4/weightlifting-fairy-kim-bok-ju-ep01-an-underwear-thiefs-identity-20161116",
"/4tzCuIpHHhc/weightlifting-fairy-kim-bok-ju-ep01-weightlifter-vs-rhythmic-gymnast-20161116",
"/QzRi9_4-ItQ/weightlifting-fairy-kim-bok-ju-ep05-lee-sung-kyung-enter-a-contest-instead20161130",
);
foreach ($links as $result) {
$explode_c = explode('/',$result);
$s = $explode_c[1];
}
echo $s;
?>
答案 0 :(得分:1)
将$s
设为数组
foreach ($links as $result) {
$explode_c = explode('/',$result);
$s[] = $explode_c[1];
}
print_r($s);
答案 1 :(得分:1)
你可以这样做,用下面的替换:
$links = array(
"/WSNINQJZj1s/weightlifting-fairy-kim-bok-ju-ep05-lee-sung-kyung-run-nam-joo-hyuk-errand-20161130",
"/Nmy5FWgX0S0/weightlifting-fairy-kim-bok-ju-ep05-nam-joo-hyuk-reject-a-proposal-20161130",
"/u3gumA7-38A/weightlifting-fairy-kim-bok-ju-ep05-did-you-fall-in-love-with-my-brother-20161130",
"/Zsa_saeRT1E/weightlifting-fairy-kim-bok-ju-ep05-sung-kyung-offered-joo-hyuk-a-deal-20161130",
"/9q0uUfSr0lE/weightlifting-fairy-kim-bok-ju-ep05-nam-joo-hyuks-angry-at-lee-sung-kyung-20161130",
"/UH6YqMDdMDE/weightlifting-fairy-kim-bok-ju-ep05-sung-kyung-and-lee-jae-yoons-drive-date-20161130",
"/5pC2NJtCg_I/weightlifting-fairy-kim-bok-ju-ep03-did-you-fight-because-of-me-20161123",
"/UbxbVugdIdo/weightlifting-fairy-kim-bok-ju-ep01-lee-sung-kyung-fell-into-the-pool-20161116",
"/f29SpSqcOQc/weightlifting-fairy-kim-bok-ju-ep03-lee-sung-kyung-got-into-trouble-20161123",
"/ydWm_Pnp1BQ/weightlifting-fairy-kim-bok-ju-ep04-lee-sung-kyung-vs-nam-joo-hyuk-20161124",
"/uiLlQSexJr4/weightlifting-fairy-kim-bok-ju-ep01-an-underwear-thiefs-identity-20161116",
"/4tzCuIpHHhc/weightlifting-fairy-kim-bok-ju-ep01-weightlifter-vs-rhythmic-gymnast-20161116",
"/QzRi9_4-ItQ/weightlifting-fairy-kim-bok-ju-ep05-lee-sung-kyung-enter-a-contest-instead20161130",
);
foreach ($links as $result) {
$explode_c = explode('/',$result);
$s[] = $explode_c[1]; // made array of exploded string
}
echo "<pre>";
print_r($s);
$result = array_search('4tzCuIpHHhc', $s); // search for the string if you need key from $s
echo $id = $s[11];// $result = 11