开发者

clearing the link id

开发者 https://www.devze.com 2023-03-27 20:02 出处:网络
if we have $id = 39827-key1-key2-key3 and we want to show only the number or anything before (-) then by using

if we have

$id = 39827-key1-key2-key3

and we want to show only the number or anything before (-) then by using

$realid = array_shift(explode("-", $id));

we will get echo $realid; // 39827

Now my problem is as following !

if w开发者_StackOverflow社区e have $id = key1/key2 and i want any way that remove the whole part key1/ and gives me only key2

how can i do it?


Ok, from your comment above, I'm assuming you want to do something like:

$id = "key1/key2";

$result = ???;

// Now $result=="$key2"

Why not just:

$parts = explode("/", $id);
$result = $parts[1];


Using the strstr() function, which was created exactly for things like this:

$id = 'key1/key2';
$realid = strstr($id, '/', true);

Do note that you have to be running PHP 5.3 or newer for this to work.


confusing question. my interpretation for $rawId containing the '/' char:

$rawId = 'key1/key2';
$realId = substr($rawId, 1 + strpos($rawId, '/')); // key2


Yet another way:

$result = implode('', array_slice(explode('/', $id), 1, 1));
0

精彩评论

暂无评论...
验证码 换一张
取 消