Reputation: 4695
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 from different tables, and the letter at the beginning of the ID represents which table, so I need to split the left side of the "-"
.
Upvotes: 0
Views: 84
Reputation: 31
Try this, after splitting the values are stored in array format in $regs
<?php
$str = $_GET['id'];
ereg("-",$str,$regs);
print_r($regs);
?>
Upvotes: 0
Reputation: 145472
The canonical method for portioning strings is:
$table = strtok($_GET["id"], "-");
$id = strtok("-");
Upvotes: 0
Reputation: 163228
Simple - use list
and explode
:
list($table, $id) = explode('-', $_GET['id']);
$id = $table . '-' . $id;
Upvotes: 5