Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Lets say in file.php, there is lots of php print text: <?php print t('Blabla'); ?>, <?php print t('Text Here'); ?>, etc.

What I need is to remove <?php print t(' and '); ?> of the php print text.

So, <?php print t('Blabla'); ?> will become Blabla, <?php print t('Text Here'); ?> will become Text Here, etc.

If one php print text in one line, I think I know how to use sed to replace, but how about if one long line contains several php print text

I just wonder how to replace it?

share|improve this question
1  
Not sure if I understand your question correctly. If you add a g at the end of the sed command, it tries to match multiple occurences on the same line. sed 's/bladibla-As-Is/bladibla-To-Be/g' –  jippie Jun 2 '12 at 14:28
    
Thanks for the reply. Yes, I know about the g. I just wonder (if can) single line command that will remove <?php print t(' and '); ?> of the php print text. (Question updated. Hope it will be easier to understand) –  apasajja Jun 2 '12 at 14:49
    
Why not just execute the php script? –  Ulrich Dangel Jun 2 '12 at 15:48
add comment

1 Answer 1

up vote 3 down vote accepted

I suppose your intention is to remove an old internationalization system from your PHP scripts.

perl -e 'undef$/;$s=<>;$s=~s/<\?php\s+(?:print|echo)\s+t\((['"'"'"])(.*?)\1\);\s+\?>/$2/gs;print$s' apasajja

This has some improvements not asked in the question:

  • Works for both print or echo.
  • Works for both single and double quotes.
  • Allows the <?php .. ?> tags to be in separate lines.
  • Allows t()'s parameter to span over several lines.

But there are still enough situations in which will fail.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.