url string
http://localhost/magento_prac/index.php/electronics/computers.html
http://localhost/magento_prac/index.php/electronics/cell-phones.html
I want to fetch 'computers' from url. ex 'computers', 'cell-phones'
url string
http://localhost/magento_prac/index.php/electronics/computers.html
http://localhost/magento_prac/index.php/electronics/cell-phones.html
I want to fetch 'computers' from url. ex 'computers', 'cell-phones'
Try something like
$category = preg_replace('/^.*\/(.*)\.html$/', '$1', $url);
The regular expression matches everything (.*) from the start (^) of the string up until the last / (\/). Then, it matches everything (.*) again except for the .html at the end and expects the string to end after that ($).
The brackets around the second .* allow you to reference that part of the match in the substitution as $1.