2011/6/2 Merlin Morgenstern <[email protected]>:
> Hi there,
>
> I am working on a pretty huge site with thousands of files with php code.
> Unfortunatelly the app throws a ton of notices du to missing '' in arrays.
> Of course I could simply disable the output on the dev server to surpress
> notices, but I would rather like to get it fixed.
>
> Has somebody a good idea on how to fix this automated somehow with regex?
>
> The vars are right now: $var[element] and should be $var['element']
>
> I was looking into sed, but I was hoping that there is also a way in php.
> Has anybody a hint on how to get the regex done?
>
> I appreciate any help on that.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I don't have the time to write a complete script, but here is an idea
(Pseudocode):
Read dir.
Foreach "File"{
open file
new var $NewFile
new var $Line
foreach "Line"{
read new line, look for "$?[?]"
tmp var $Pos = strpos($Line, '[')+1
tmp var $Pos2 = strpos($NewFile, ']')
tmp var $Ctrl = true
while($Ctrl){
if( $Line[$Pos] !='$' && $Line[$Pos] != '\''] && $Line[$Pos] !=
'"']){ //or some reg match (it's probably the wisest to use so you can
find blank spaces before $ ' or "){
add the content of the line before $Pos-1 to $NewFile
add ' or " to $NewFile
add content between $Pos-1 and $Pos2 to $NewFile
add ' or " and the ']' to $NewFile
search the rest of the line for more arrays in the same way
$Pos = strpos($Line, '[', $Pos2)
$Pos2 = strpos($Line, ']' , $Pos)
if($Pos == false || $Pos2 == false){
$Ctrl = false
}
}else{
copy the whole line to $NewFile
}
add \r\n to $NewFile
}
}
save file
}
--
**********************************************
Hans Åhlin
Tel: +46761488019
icq: 275232967
http://www.kronan-net.com/
irc://irc.freenode.net:6667 - TheCoin
**********************************************
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php