Latox
Latox

Reputation: 4695

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 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

Answers (3)

user598006
user598006

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

mario
mario

Reputation: 145472

The canonical method for portioning strings is:

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

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163228

Simple - use list and explode:

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

codepad example

Upvotes: 5

Related Questions