0

我想从我的 URL 中返回这些唯一值

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)

更新了我上面的问题,更容易理解

4

1 回答 1

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;

?>
于 2012-11-08T16:03:10.367 回答