fork download
<?php
// Control de rutas (URL) en PHP para ejecutar peticiones API
// https://es.stackoverflow.com/q/119958/127


$url   = 'http://w...content-available-to-author-only...e.com/padres/col/8';
$regex = '~^https?://[^/]+/(?P<modulo>[-\p{L}]+)(?:/(?P<coleccion>[-\p{L}]+))?(?:/(?P<id>\d+))?/?$~i';

if (preg_match( $regex, $url, $matches)) {
	$modulo    = $matches['modulo'];
	$coleccion = isset($matches['coleccion']) ? $matches['coleccion'] : '';
	$id        = isset($matches['id']) ? $matches['id'] : '';
	
	echo "Modulo:\t\t'$modulo'\nColección:\t'$coleccion'\nId:\t\t\t'$id'";
	echo "\n\n\$matches = ";
	var_export($matches);
} else {
	// URL inválida
}
Success #stdin #stdout 0.02s 23748KB
stdin
Standard input is empty
stdout
Modulo:		'padres'
Colección:	'col'
Id:			'8'

$matches = array (
  0 => 'http://w...content-available-to-author-only...e.com/padres/col/8',
  'modulo' => 'padres',
  1 => 'padres',
  'coleccion' => 'col',
  2 => 'col',
  'id' => '8',
  3 => '8',
)