我想从我的网址
返回这些唯一值394_black
500_mono2
网址:
/shop/swarovski/394_black_the-reagan-swarovski-maxi-dress
/shop/celeb/500_mono2_the-reagan-swarovski-maxi-dress
我可以在PHP中执行此操作吗?
伪代码
$url = get url
$firstvar = after 3rd / and after second _ save text (500_mono2) from $url
$secondvar = using $firstvar return only first 3 numbers
//substr($firstvar, 0, 3); (I think this will be it)
答案 0 :(得分:2)
<?php
$url = '/shop/celeb/500_mono2_the-reagan-swarovski-maxi-dress';
$urlparts = explode('/', $url);
list($var1, $var2, $var3) = explode('_', end($urlparts));
echo $var1 . '<br>' . $var2 . '<br>' . $var3;
?>