Hola.
Necesito ayuda en este codigo con expresiones regulares, que no funciona:
<?php
$routes = array(array("url" => "/^posts\/(?P<id>\d+)\/?$/",
"controlador" => "posts",
"vista" => "show"),
array("url" => "/^posts\/new\/?$/",
"controlador" => "posts",
"vista" => "new"),
array("url" => "/^posts\/create\/?$/",
"controlador" => "posts",
"vista" => "create"),
array("url" => "/^posts\/(?P<id>\d+)\/edit\/?$/",
"controlador" => "posts",
"vista" => "edit"));
$cadena = "/posts/1";
foreach($routes as $route)
{
if (preg_match($route['url'], $cadena, $arreglo)) {
print "<p>Url encontrada.</p>\n";
print_r($arreglo);
} else {
print "<p>Url no encontrada.</p>\n";
}
}
?>
Gracias