I get this error: Warning: preg_replace() [function.preg-replace]: No ending delimiter '.' found in but I can't figure out why

Here is the code:

foreach( $content as $item )
                    $item = preg_replace( array('.',' '), array('-','-'), strtolower($item));
                    $replace = '<h4 id="'.utf8_decode($item).'">';
                    $phrase = preg_replace('/'.$tag.'/', $replace, $phrase, 1);

Please also tell my WHY it doesn't work

closed as off-topic by fuxia Nov 8 '14 at 4:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • @toscho. True. I was creating this within WordPress but I realize now that this indeed has nothing to do with WordPress. My Bad. – Interactive Nov 10 '14 at 8:45


preg_replace expects your first parameter to be a pattern.

Try a simple replace:

$item = str_replace( array('.',' '), array('-','-'), strtolower($item));
  • 1
    It's the simple things in life that make a difference. I thank you good sir. – Interactive Nov 7 '14 at 13:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.