1

I am trying to implement preg_match for string containing special characters : "&$".

The code that i am using :

$f = fopen($path,"r");

while($lines = fgets($f))
{
    if(preg_match("/\&\$/",trim($lines),$matches))
    {
        echo "Yes<br>";
    }
}

I have already tried preg_match("/&\$/",$lines,$matches)

I am getting nothing as a result. (The file related to "$path" that i am using contains 2 lines containing "&$").

Plz help !!

Prashant Goel
  • 471
  • 4
  • 7

1 Answers1

2

You are using a dollar expression within the double-quoted pattern.

The following works for me:

if(preg_match('/&\$/',trim($lines),$matches))

Check this existing question on the difference between single and double quotes: What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
matfax
  • 634
  • 11
  • 17