doa24uk Posted March 11, 2010 Share Posted March 11, 2010 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! Quote Link to comment Share on other sites More sharing options...
brianlange Posted March 11, 2010 Share Posted March 11, 2010 $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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.