- Impact
- 38
Hi folks,
Plese see the regex below and let me know where I'm going wrong! I have been banging my head on this for a few hours already and I am just stumped.
I want it to become:
Any help would be appreciated and repped, thanks!
Plese see the regex below and let me know where I'm going wrong! I have been banging my head on this for a few hours already and I am just stumped.
PHP:
$subcategories = '<li><a href="test">Test - Sports</a></li>
<li><a href="test">Something - Fashion</a></li>
<li><a href="test">Random - Technology</a></li>';
$subcategories = preg_replace('/<a (.*?)/>(.*?)/<\/a/>','<a '.$1.'>'.(isset(explode(' - ', $2)[1])) ? explode(' - ', $2)[1]:$2.'</a>', $subcategories);
I want it to become:
HTML:
<li><a href="test">Sports</a></li>
<li><a href="test">Fashion</a></li>
<li><a href="test">Technology</a></li>
Any help would be appreciated and repped, thanks!
Last edited:






