开发者

preg_match check if string is surrounded in double or single quotes

开发者 https://www.devze.com 2023-02-14 01:18 出处:网络
Can someone tell me the regex to see if something is surrounded in double or single quotes. \"this is the string\"

Can someone tell me the regex to see if something is surrounded in double or single quotes.

"this is the string"

i want it to return false if it quotes are not present at all or not present at the start and the en开发者_如何转开发d.


preg_match('/^(["\']).*\1$/m', $string);

will return 1 if the string is surrounded by double quotes and 0 if it is not.


Use:

if (preg_match('#^(\'|").+\1$#', $string) == 1)
0

精彩评论

暂无评论...
验证码 换一张
取 消