Jump to content

Match HTML\1.0 or HTML\1.1


doa24uk

Recommended Posts

  $headers = array("HTML\\1.0","HTML\\1.1");

  $pattern = '/HTML\\\1\.[01]/';

  $newHeaders = preg_replace($pattern, "", $headers);

 

You have to escape the backslash in the subject and then use three backslashes in the pattern.

You have to use a backslash before the period to escape it in the pattern, otherwise the period is treated as a special character, without the backslash it means any single character. The brackets around 0 and 1 mean either character will be matched.

 

You could also add the start identifier ^ and end identifier $ to the pattern $pattern = '/^HTML\\\1\.[01]$/';

Without these the pattern the above will match strings like HTML\1.123456

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.