Jump to content

Match HTML\1.0 or HTML\1.1


doa24uk

Recommended Posts

Hey guys,

 

My two possibilities are to match either HTML\1.0 or HTML\1.1

 

I was using str_replace to just match one but now I believe I need preg_replace.

 

$responsecode = str_replace("HTTP/1.1", "", $headers[0]);

 

However I'm completely lost with the regex for this! Help!

Link to comment
Share on other sites

  $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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.