开发者

Splitting data from URL?

Say my url is site.php?id=X-34837439843

How do i split it so I return

$table = "X";
$id = "X-34837439843";

Basically I'm using the same page to select fro开发者_Python百科m different tables, and the letter at the beginning of the ID represents which table, so I need to split the left side of the "-".


Simple - use list and explode:

list($table, $id) = explode('-', $_GET['id']);
$id = $table . '-' . $id;

codepad example


The canonical method for portioning strings is:

$table = strtok($_GET["id"], "-");
$id = strtok("-");


Try this, after splitting the values are stored in array format in $regs

<?php
$str = $_GET['id'];

ereg("-",$str,$regs);
print_r($regs);

?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜