Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Ask for a regex

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Ask for a regex

Postby bconsulting » Wed Jul 23, 2014 3:30 am

Hi,

I have to delete the first line of many files and replace it with a new value.

What I have to delete first line beginning with '<?php $var=new '
I have to replace it with : '<?php'

Is someone know how to do it with sed, grep or something like that.

Thank you.

Gérald.
bconsulting
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jul 23, 2014 3:19 am

Re: Ask for a regex

Postby disc0nector » Sat Aug 02, 2014 4:40 pm

$phpcode = "<?php $var=new stuff();
something;
?>";
$pattern = '/[<|?]{2}php .+/m';
$replacement = '<?php';
$result = preg_replace($pattern, $replacement, $phpcode);

//this should solve your problem
disc0nector
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Aug 02, 2014 4:31 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron