Jump to content

Recommended Posts

can someone help me rewrite this line of code to look for <?php I understand the first part of the code but after the bracet i'm getting confused. The -4 is that combining all the characters its subtracting and if so would i use -7 with a <?php change?

 

        if (substr($s,0,2)=='<?' && substr($s,strlen($s)-2,2)=='?>') {$s = substr($s,2,strlen($s)-4); eval($s);$s = '';}

Link to comment
https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/
Share on other sites

ah right, that probably needs to change to -7

 

is this the best way to combine the two?

 

        if (substr($s,0,2)=='<?' && substr($s,strlen($s)-2,2)=='?>') {
        	$s = substr($s,2,strlen($s)-4); 
eval($s);$s = '';
} elseif 
(substr($s,0,5)=='<?php' && substr($s,strlen($s)-2,2)=='?>') {
$s = substr($s,2,strlen($s)-7); 
eval($s);$s = '';
}

Link to comment
https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652643
Share on other sites

Well...only reason I can see value in that is if you are anticipating the use of both the regular and short tags, but tbh, I'd probably rather look into getting rid of the short tags to begin with.  Regardless, it might be cleaner and shorter to use a preg_match, but I'm not really the person to be talking to about that.  Hopefully someone more versed in regex will come along with better insight.

Link to comment
https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652649
Share on other sites

Well...only reason I can see value in that is if you are anticipating the use of both the regular and short tags, but tbh, I'd probably rather look into getting rid of the short tags to begin with.  Regardless, it might be cleaner and shorter to use a preg_match, but I'm not really the person to be talking to about that.  Hopefully someone more versed in regex will come along with better insight.

 

my plan was to switch all tags to <?php but I figure its safer to have the code check for both short and regular just in case I over look a short tag. I guess another option would be running a command line code that would search all directories for .tpl and .php files and replace "<? " (with a space) with <?php

Link to comment
https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652661
Share on other sites

Well...only reason I can see value in that is if you are anticipating the use of both the regular and short tags, but tbh, I'd probably rather look into getting rid of the short tags to begin with.  Regardless, it might be cleaner and shorter to use a preg_match, but I'm not really the person to be talking to about that.  Hopefully someone more versed in regex will come along with better insight.

 

my plan was to switch all tags to <?php but I figure its safer to have the code check for both short and regular just in case I over look a short tag. I guess another option would be running a command line code that would search all directories for .tpl and .php files and replace "<? " (with a space) with <?php

 

You could use Perl for this.

 

#!/usr/bin/perl
@files = glob '*.php';
undef $/;
for $file (@files) {
    
    open(FILE, "+<$file") || next;
    $_ = <FILE>;
    s/<\?(?=\s+)/<?php/g;
    print FILE $_;

}

 

I just wrote that up in like 2 minutes, so it probably has an error or something I overlooked.  Play around with it.   

Link to comment
https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652860
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.