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?

  • 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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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