Php regex or | operator
I am doing preg_replace:
$pattern = '/<ul>/'; $replacement = ""; $string = "hello <ul> how are you doing </ul>"; echo preg_replace($pattern, $replacement, $string); This will replace my <ul> with "" , but Id would like to replace everything with <ul> or </ul> , but I donβt understand how to use the | (or).
I try like this, but it does not work correctly:
$pattern = '/<ul>|</ul>/'; $replacement = ""; $string = "hello <ul> how are you doing </ul>"; echo preg_replace($pattern, $replacement, $string); Any help would certainly be appreciated.
Thanks Bryan
You may need to avoid the slash in / ul, like this:
$pattern = '/<ul>|<\/ul>/'; or do it, not sure if this will work:
$pattern = '/<\/?ul>/'; ("?" means zero or one of the previous characters, which in this case is equal to "/".)
You need to avoid the backslash.
/<ul>|<\/ul>/