What does the "~" character mean in the following?:
preg_match_all("~<img [^>]+>~", $inputw, $output);
My guess is that they are beginning and end markers such as ^ and $.
What does the "~" character mean in the following?:
preg_match_all("~<img [^>]+>~", $inputw, $output);
My guess is that they are beginning and end markers such as ^ and $.
It is a delimiter
A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
As Nambi said you are free to choose the delimiter in a regex. However if the delimiter appears in the pattern it has to escaped. Knowing this, imagine the following situation
'/\/var\/www\/test/' # delimited with /
'~/var/www/test~' # delimited with ~
The last one does not require to escape the /
as the delimiter is now ~
. Much cleaner isn't it?
As a general guideline you are encouraged to choose a delimiter which isn't pattern of the pattern itself, I guess ~
is widely distributed as an alternative to /
as it rarely appears in real world pattern.
The dirty little delimiter secret they don't tell you ->
http://uk.php.net/manual/en/regexp.reference.delimiters.php
Examples:
Paired delimiters (raw: \d{2}Some\{33\}\w{5}
)
{\d{2}Some\\{33\\}\w{5}}
parses to \d{2}Some\\{33\\}\w{5}
and
{\d{2}Some\{33\}\w{5}}
parses to \d{2}Some{33}\w{5}
Un-Paired delimiters (raw: \d{2}Some\+33\+\w{5}
)
+\d{2}Some\+33\+\w{5}+
parses to \d{2}Some+33+\w{5}
and
+\d{2}Some\\+33\\+\w{5}+
won't parse because the delimiter is un-escaped.
© 2022 - 2024 — McMap. All rights reserved.
My guess is that they are beginning and end markers such as ^ and $.
Seems like you answered your own question. – Carlie^
and$
... – Stockmon