Hello forums.. Can anybody give a hint for how to replace the first <ul> and last </ul> tag from the string $string:
$string = '<ul> <li></li> <li> <ul> <li> </li> <li></li> </ul> </li> <li></li> </ul>';
Thanks in advance to all of you.
Hi, try this,
$patterns[0] = '/<ul>/'; $patterns[1] = '/</ul>/'; $replacements[0] = 'Enter the replacement for <ul> here'; $replacements[1] = 'Enter the replacement for </ul> here'; echo preg_replace($patterns, $replacements, $string);
Regards
this will repalce the first and last ul tags with zerolength space.
$pattern = "/^<ul>|<\/ul>$/" ; $string = preg_replace($pattern, '', $string) ;