Skip to content
Advertisement

Tag: preg-replace

Anonymize IPv4 and IPv6 addresses with PHP preg_replace?

I needed to anonymize IPv4 and IPv6 addresses so I coded this crude solution: It works fine with full length IPv4 and IPv6 addresses like 207.142.131.005 2001:0db8:0000:08d3:0000:8a2e:0070:7344 but not with abbreviated addresses like 207.142.131.5 2001:0db8::8d3::8a2e:7:7344 I wonder if there is an elegant solution with preg_replace and some regular expression magic? Answer No conditional is necessary. You can write two patterns

PHP How to add plus (+) character before double quotes and words without double quotes in string [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 6 years ago. Improve this question I have below string: And I want to add plus (+) character before

preg_replace get each two characters from a word

Actually I’m trying to come up with a way of getting a string like “GEWO” out of the “Get Word” by using preg_replace function. The thing is there also can be a strings like “Get”, or “Get Word And another Word” so I have to get the proper string respectively. Thanks! Answer Use this: ouput: GEWOANANWO

Warning: preg_replace(): Unknown modifier

I have the following error: Warning: preg_replace(): Unknown modifier ‘]’ in xxx.php on line 38 This is the code on line 38: How can I fix this problem? Answer Why the error occurs In PHP, a regular expression needs to be enclosed within a pair of delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character; /, #, ~ are

Find and replace (part of) string in comment blocks with regex

I’m trying to find a certain string that can occur inside a comment block. That string can be a word, but it can also be part of a word. For instance, suppose I’m looking for the word “codex”, then this word should be replace with “bindex” but even when it’s part of a word, like “codexing”. This should be changed

Advertisement