开发者

preg_match check if string is surrounded in double or single quotes

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜