PHP regex to extract controller and action from string -


so developing symfony2 application. if know talking know how routes structured there need extract routes , controllers , actions.

i found how extract route object can't extract controller , action, have string has them.

so have string: acme\somebundle\controller\defaultcontroller::indexaction

all string have similar structure. strings end controllername::actionname. controller name ends "controller" , action name end "action". couldnt figure how extract theese values string. new regex read don't have clue how this. please me, apreciated :)

example string:

`emca\anotherbundle\controller\securitycontroller::loginaction` 

example output:

securitycontroller loginaction 

i think can't 1 regex 2 may enough. thank you!

an example can found in symfony's controllernameparser class:

$controller = 'acme\yourbundle\controller\securitycontroller::loginaction';  if (0 === preg_match('#^(.*?\\\\controller\\\\(.+)controller)::(.+)action$#', $controller, $match)) {     throw new \invalidargumentexception(sprintf('the "%s" controller not valid "class::method" string.', $controller)); }  $classname      = $match[1]; $controllername = $match[2]; $actionname     = $match[3]; 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -