Find extra space / new line after a closing ?>

2020-02-10 17:36发布

So I have a space/new line after a closing ?> (php tag) that is breaking my application.

How can I find it easily I have 1000 of files and 100000 lines of code in this app.

Ideally im after some regex combined with find grep to run on a unix box.

9条回答
走好不送
2楼-- · 2020-02-10 18:18

This works for me...

<\?php | \?>

If you need to use in in a sublime-settings file or something like that which doesn't like forward slashes, you might have to add an extra slash for each of them like so...

<\\?php | \\?>

Hope that helps!

查看更多
贼婆χ
3楼-- · 2020-02-10 18:20

Using notepad++ you can replace easily all documents at the same time, drap and drop that folder of files and press CTRL + R, also you can use Regex

查看更多
再贱就再见
4楼-- · 2020-02-10 18:22
sed -e :a -e '/^[ \n]*$/{$d;N;ba' -e '}' -e '$ s/\([^ ]\)*?>[ ]*/\1?>/' file.php > new_file.php

to be executed for each file not completely tested..

remember to work on a temporary file and after the sed operation copy the new file on the original one..

查看更多
登录 后发表回答