Ask for a regex

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

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.

disc0nector
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Aug 02, 2014 4:31 pm

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


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests