I'm having some trouble with redirection in config/routes.php file
I can't find the right regex
$_skill = '[A-Za-z\-]+'
Router::connect('/-:skill/:city-:zipcode:shit', array('controller' => 'redirects', 'action' => 'district'),
array('city' => '[A-Za-z-0-9\]+.(er|eme)-arrondissement',
'skill' => $_skill,
'zipcode' => $_zipcode,
'shit' => '(.*)',
'pass' => array('zipcode'),
)
);
I would like to match any url where city ends with 'arrondissement' but i'm a total noob in regex
thank you.
With most regex you can use the dollar symbol to match the end of a string.
simply 'arrondissement$'
And drop all the stuff at the beginning.
Related
I'm trying to build a list of array of mime types for PHP. I got a long list of mime types but I need to remove all the 'xxx' => upfront. How to detect them using regexp cos I tried '[\u][a-z0-9]' => and it didn't work.
'cpt' => 'application/mac-compactpro',
'cpt' => 'application/x-compactpro',
'cpt' => 'application/x-cpt',
'crl' => 'application/pkcs-crl',
'crl' => 'application/pkix-crl',
'crt' => 'application/pkix-cert',
'crt' => 'application/x-x509-ca-cert',
'crt' => 'application/x-x509-user-cert',
'csh' => 'application/x-csh',
'csh' => 'text/x-script.csh',
'css' => 'application/x-pointplus',
Try this ....
Find:^\s*'\w+' =>
Replace with:empty
You may try the following find and replace, in regex mode:
Find: ^\s*'.*?'\s*=>\s*('.*?',?)$
Replace: $1
Demo
Let's keep it simple. You need to search for ^\s*'\w\w\w' =>
Don't forget to set the Search Mode to Regular Expression in the search dialog.
Is there a way to use hash mark in route pattern? I tried to use backslash before hash mark \#, but no result.
My code:
use Phalcon\Mvc\Router\Group;
$gr = new Group([
'module' => 'home',
]);
$gr->addPost("/item/view/([0-9]*)/#([0-9]*)", [
'module' => 'item',
'controller' => 'view',
'firstId' => 1,
'secondId' => 2,
])->setName('item:view:hash');
$router->mount($gr);
Usage:
echo $this->url->get(['for' => 'item:view:hash', 'firstId' => 1, 'secondId' => 2])
gives me a correct url: /item/view/1/#2, but I receive a warning:
Unknown modifier '('
Is there a way to remove warnings, to use the hash mark in the right way? Thanks in advance.
Nothing after the # mark is sent to the server, so including it in a server-side route doesn't do anything. The fragment/anchor is client-side only.
I need some help about my routes in Zend (Zend1) ...
I need that I can use my route like that :
http://mywebsite.com/myfolder/region/job/
http://mywebsite.com/myfolder/region/job/add
http://mywebsite.com/myfolder/region/job/add/page
http://mywebsite.com/myfolder/region/job/page
Parameters add and page are optional ...
This is what I did
$route = new Zend_Controller_Router_Route_Regex(
'myfolder/([^/]+)/([^/]+)/?([^/]+)?/?([0-9]+)?',
array('controller' => 'myfolder','action' => 'search'),
array(1 => 'region',2 => 'job', 3 => 'add', 4 => 'page'),
'myfolder/%s/%s/%s/%s'
);
Obviously, it doesn't work ...
What I want? I want that last the two parameters (add and page) are optional ...
Can you help me? what's wrong with my regex?
EDIT 1:
Ok, so I tried it, but isn't ok ...
I need that parameters add and page are optional ...
$route = new Zend_Controller_Router_Route(
'myfolder/:region/:job/:add/:page',
array(
'controller' => 'myfolder',
'action' => 'search',
'region' => 'XX',
'job' => '',
'add' => '',
'page' => 1
),
array(
'region' => '[a-zA-Z-_0-9-]+',
'job' => '[a-zA-Z-_0-9-]+',
'add' => '[a-zA-Z-_]+',
'page' => '\d+'
)
);
With that, this one http://mywebsite.com/myfolder/region/job/page doesn't work ...
EDIT 2:
I also tried with 'myfolder/:region/:job/*', but the result is same, doesn't work as I want ...
I really wonder if it is possible ...
EDIT 3:##
$route = new Zend_Controller_Router_Route_Regex('myfolder/([^/]+)/([^/]+)(?:/|$)(?:(?!\d+(?:/|$))([^/]+)(?:/|$))?(?:(\d+)(?:/|$))?$',
array('controller' => 'myfolder', 'action' => 'recherche', 'presta' => ''),
array(1 => 'region',2 => 'job', 3 => 'presta', 4 => 'page'),
'myfolder/%s/%s/%s/%s');
Prepare yourself.
The RegEx
myfolder/([^/]+)/([^/]+)(?:/|$)(?:(?!\d+(?:/|$))([^/]+)(?:/|$))?(?:(\d+)(?:/|$))?$
See it working on RegExr (on RegExr, I had to add \n\r to one of the negated classes so it didn't match all my line breaks, in practice you probably won't be dealing with line breaks though.)
The important thing to note on RegExr is that in the 4th case, the page number is in the 4th capture group, with nothing in the 3rd group.
Explanation
myfolder/([^/]+)/([^/]+) All looking good up to here, no changes yet.
(?:/|$) Match a / or end of input.
Next, overall we have a non-capturing group that is optional. This would be the add section.
(?:(?!\d+(?:\|$))([^/]+)(?:/|$))?
Now lets break it down further:
(?!\d+(?:/|$)) Make sure its not a page number - digits only followed by / or end of input. (Negative lookahead)
([^/]+) Our capture group - add in the example.
(?:/|$) Match a / or end of input.
Now for our page number group, again it's optional and non-capturing:
(?:(\d+)(?:/|$))? Captures the numbers, then matches / or end of input again.
$ And just in case it tries to match substrings of actual matches, I threw in another end of input anchor (since you can match as many in a row as you like), although the regex functions without it.
Generating The Path
What you basically want is a way of doing this:
At the moment the 2nd and 3rd parameters are:
array(1 => 'region',2 => 'job', 3 => 'add', 4 => 'page'),
'myfolder/%s/%s/%s/%s'
You want them to be something like:
array(1 => 'region',2 => 'job', 3 => '/'+'add', 4 => '/'+'page'),
'myfolder/%s/%s%s%s'
Where you only add the / if the optional group is present. The code above won't work but perhaps there is some way you could implement that.
I'm developing a site for analyzing a store's data.
I need the url part of my array to look like this:
array(
'url' => 'http://some.website.com:8080/SASStoredProcess/do?_username=user-123',
'_password' => 'passwd',
'_program' => '/Utilisateurs/DARTIES3-2012/Mon dossier/analyse_dc',
'annee' => '2012',
'ind' => 'V',
'_action' => 'execute'
);
I currently have this and am struggling to convert it to the desired format:
array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
Please can somebody help me to convert the URL in the second code block to look like the first code block? Thanks in advance.
So this will extract the url in the form you want, as $url:
$myArray = array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
parse_str($myArray['url']);
echo $url;
You will need to decide where it needs to go next and how you get it there.
You might want to use: parse_url() and parse_str() over your $array['url']
My link:
echo $link->link($planDetailsByCompany['PlanDetail']['name'],
array('controller' => 'plan_details', 'action' => 'view_benefit_schedule',
'id' => $planDetailsByCompany['PlanDetail']['id'],
'slug' => $planDetailsByCompany['PlanDetail']['name']));
My custom route:
Router::connect('/pd/:id-:slug',
array('controller' => 'plan_details', 'action' => 'view_benefit_schedule'),
array('pass' => array('id', 'slug'),
'id' => '[0-9]+'));
My url is displaying like so:
..pd/44-Primary%20Indemnity
I cannot determine how to remove the %20 and replace it with a "-". There is a space in the company name that is causing this. Is this possible within the CakePHP router functionality? If so, how? Or another method.
Geeze.. I just solved this!
In my link above, replace the 'slug' line with:
...'slug' => Inflector::slug($planDetailsByCompany['PlanDetail']['name'])...
The Inflector handles the spaces in the url. And my result url is:
...pd/44-Primary_Indemnity