Questions tagged [preg-quote]

12 questions
3
votes
1 answer

preg_quote ignores trailing dot in preg_match_all

Regex preg_match_all('@(\b' . preg_quote($needle,'@') . '\b)@is', $haystack, $matches); Haystack (Job: NAS-Inkrementell) Operation succeeded. Needle Operation succeeded --> works Operation succeeded. --> does not work I did some tests: Alternative…
PrimuS
  • 2,505
  • 6
  • 33
  • 66
2
votes
2 answers

Why does PHP's preg_quote escape unnecessary characters?

From http://php.net/manual/en/function.preg-quote.php: preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in…
CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
2
votes
1 answer

Regex not displaying well whe using PHP preg_quote

Hi Im trying to concatinate a string before converting that string into regex in PHP, but the problem is it's not displaying as expected. I've been searching using google and found out about preg_quote, problem is it's not working well. Here is my…
loki9
  • 625
  • 7
  • 20
0
votes
1 answer

How to exclude vertical bar from escaping in preg_quote()

I have an array the elements of which are paths and contain forward slashes and exclamation marks. And I need to inject such an array as regex pattern to preg_match() $url = 'example.com/path/to/!another'; $arr = ['path/to/!page',…
stckvrw
  • 1,689
  • 18
  • 42
0
votes
2 answers

Preg_match doesn't work when pattern and subject inside preg_quote - PHP

I am trying to preg_match by using preg_quote for my pattern and subject. Problem is that preg_match doesn't seem to match them. I removed the preg_quote and it matched me just fine. I preg_quote subject and message to see what it's the output and…
Eleni Ioakim
  • 53
  • 1
  • 7
0
votes
1 answer

preg_quote issue in Laravel project

I'm testing preg_quote() function in search function in Laravel. I found out a strange behavior - "+" is not escapes, but remove from the output. preg_quote("a + b"); // "a b" Tried to call same function without laravel staff from cli php…
Denys Siebov
  • 198
  • 4
  • 16
0
votes
0 answers

Highlighting search result excerpt causes PHP error

I have the following code in a WordPress theme functions.php. I'm using PHP 7.1 both locally and remotely. if ( ! function_exists( 'highlight_search_results' ) ) : // this filter runs on the_excerpt and the_title // to highlight inside…
Jonathan Stegall
  • 530
  • 1
  • 6
  • 23
0
votes
3 answers

How to escape special characters that that are not gathered in a special shape

I have this string: $var = "Foo (.* ) bar blla (.* ) b*l?a$ bla bla "; I want to escape the * and ? and all special characters that are not gathered in this shape "(.*)" I wanted to use preg_quote($var, '\') But it escapes all the special…
Mana
  • 167
  • 3
  • 13
0
votes
2 answers

preg_replace not working as expected with wildcards

I have the following code: //Array filled with data from external file $patterns = array('!test!', 'stuff1', 'all!!', ''); //Delete empty values in array $patterns = array_filter($patterns); foreach($patterns as &$item){ $item =…
Perocat
  • 1,481
  • 7
  • 25
  • 48
0
votes
1 answer

Make search in text file case-insensitive

I'm using the following function to search for words in a text file. The problem is that this function is case-sensitive. I don't want it to be case-sensitive! How can I make the function case-insensitive? $url = 'files/file.txt'; $thedata =…
Airikr
  • 6,258
  • 15
  • 59
  • 110
0
votes
2 answers

preg_replace with preg_quote except one column

I'm trying to make some tricks with preg_replace used with preg_quote. I have an array of json data object and what I want to Replace all values of keys except the value of one key Below is the basic structure of the input array: $posts =…
Zolax
  • 91
  • 3
  • 12
-1
votes
1 answer

Why this pattern with __FILE__ under preg_quote() is not matching the directory path?

This pattern with __FILE__ under preg_quote( $str, '/' ) /^C\:\\xampp\\apps\\wordpress\\htdocs\\wp\-content\\themes\\themename\\inc\\fonts\/uploads\/[^\/\\]+(\/|\\)/ is not matching this directory…