Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding all PHP short tags

Tags:

regex

php

vim

I need to find all short PHP tags.

The regex for it <\?(?!php) but I can not use it in vim.

How to "convert" it to vim?

like image 511
pepper Avatar asked May 24 '11 13:05

pepper


People also ask

What is PHP short tag?

The <= tag is called short open tag in PHP. To use the short tags, one must have to enable it from settings in the PHP. ini file. First of all ensure that short tags are not disabled, To check it, go into php. ini file On line 77 .

How many tags are there in PHP?

There are four different pairs of opening and closing tags which can be used in php.

What are the various tags used in PHP?

php and ?>. These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser. PHP script within these tags can be embedded in HTML document, so that embedded code is executed on server, leaving rest of the document to be processed by client browser's HTML parser.


2 Answers

For me this one worked fine:

<\?(?!php|xml)
like image 91
Janos Szabo Avatar answered Sep 17 '22 14:09

Janos Szabo


The best way to find short-tags in vim is to find all occurrences of <? not followed by a p:

/<?[^p]

The reason your regex is failing in vim is because /? finds literal question marks, while \? is a quantifier; /<\? in vim will attempt to find 0 or 1 less-than signs. This is backwards from what you might expect in most regular expression engines.


If you want to match short tags that are immediately followed by a new line, you cannot use [^p], which requires there to be something there to match which isn't a p. In this case, you can match "not p or end-of-line" with

/<?\($\|[^p]\)
like image 23
meagar Avatar answered Sep 16 '22 14:09

meagar