Batch script to replace PHP short open tags with <?php

前端 未结 13 1867
轻奢々
轻奢々 2020-11-30 01:49

I have a large collection of php files written over the years and I need to properly replace all the short open tags into proper explicit open tags.

change \         


        
13条回答
  •  日久生厌
    2020-11-30 02:43

    If you're using the tokenizer option, this might be helpful:

    $content = file_get_contents($file);
    $tokens = token_get_all($content);
    $output = '';
    
    foreach($tokens as $token) {
     if(is_array($token)) {
      list($index, $code, $line) = $token;
      switch($index) {
       case T_OPEN_TAG_WITH_ECHO:
        $output .= '

    Note that the tokenizer will not properly tokenize short tags if short tags aren't enabled. That is, you can't run this code on the system where short tags aren't working. You must run it elsewhere to convert the code.

提交回复
热议问题