What are the different between this two diff statement? Any reference document?
'{<table width="100%" border="0" cellspacing="0" cellpadding="0">.*?</table>}si' -> Success
'%<table width="100%" border="0" cellspacing="0" cellpadding="0">.*?</table>%si' -> Fail
Well, you are using a delimiter that's used inside of your string, (100%
), if you decided to use % as a delimiter, you need to escape any instance of % inside the string with a backslash. The following will work:
'%<table width="100\%" border="0" cellspacing="0" cellpadding="0">.*?</table>%si'
See the documentation:
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
Often used delimiters are forward slashes (/), hash signs (#) and tildes (~). The following are all examples of valid delimited patterns.
/foo bar/ #^[^0-9]$# +php+ %[a-zA-Z0-9_-]%
In addition to the aforementioned delimiters, it is also possible to use bracket style delimiters where the opening and closing brackets are the starting and ending delimiter, respectively.
{this is a pattern}
So they're both equivalent, it's just that one uses a delimiter of the first style and the other uses braces. But both are delimiting the regex. Regex options come after the closing delimiter in both cases.