views:

106

answers:

2

if i have a <form action='./search' method='get'>
with <input type='text' name='keyword' value='this is the search term' />inside

after submitting the form, it leads me to /search?keyword=this%20is%20the%search%20term

what regex should i use to capture that form of url and rewrite it to
/search-this_is_the_search_term

A: 

link text

Above Link will help...

Rachel
+1  A: 

First urldecode the search string and then replace the spaces with underscores. E.g.:

$str = "this%20is%20the%search%20term";
$decoded = urldecode($str);
$final = str_replace(' ', '_', $decoded);

You can do the same with a regular expression using preg_replace only more reliably as you may need to remove multiple consecutive spaces:

$str = "this%20is%20the%search%20term";
$decoded = urldecode($str);
$final = preg_replace("/\s+/", "_", $decoded);
karim79