PHP novice help needed

I have been learning PHP for some time now and I need some clarification.

I saw a function preg_matchcalled with different separators, such as:

preg_match('/.../')

and

preg_match('#...#')

Today I also saw %.

My question has two parts:

What all characters can be used?

And is there a standard?

+2
source share
1 answer

Any

  • not alphanumeric
  • non-spaces and
  • feedback ASCII character

can be used as a separator.

Also, if you use opening punctuation marks as an opening delimiter:

( { [ <

then their corresponding closing punctuation characters should be used as a closing delimiter:

) } ] >

/.
, / .

:

// check if a string is number/number format:
if(preg_match(/^\d+\/\d+$/)) {
  // match
}

, , .

, , , :

if(preg_match(#^\d+/\d+$#)) 
+4

All Articles