acctman Posted September 29, 2008 Share Posted September 29, 2008 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 = '';} Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/ Share on other sites More sharing options...
.josh Posted September 29, 2008 Share Posted September 29, 2008 I think this is what you are looking for: if (substr($s,0,5)=='<?php' && substr($s,strlen($s)-2,2)=='?>') {$s = substr($s,2,strlen($s)-4); eval($s);$s = '';} Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652636 Share on other sites More sharing options...
acctman Posted September 29, 2008 Author Share Posted September 29, 2008 I think this is what you are looking for: if (substr($s,0,5)=='<?php' && substr($s,strlen($s)-2,2)=='?>') {$s = substr($s,2,strlen($s)-4); eval($s);$s = '';} so the strlen($s)-4); doesn't change? Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652638 Share on other sites More sharing options...
.josh Posted September 29, 2008 Share Posted September 29, 2008 ah right, that probably needs to change to -7 Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652640 Share on other sites More sharing options...
acctman Posted September 29, 2008 Author Share Posted September 29, 2008 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 = ''; } Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652643 Share on other sites More sharing options...
.josh Posted September 29, 2008 Share Posted September 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652649 Share on other sites More sharing options...
acctman Posted September 29, 2008 Author Share Posted September 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652661 Share on other sites More sharing options...
CroNiX Posted September 29, 2008 Share Posted September 29, 2008 what about <?= ? Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652667 Share on other sites More sharing options...
DarkWater Posted September 29, 2008 Share Posted September 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/126206-solved-line-rewrite/#findComment-652860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.