weballergy Posted December 15, 2006 Share Posted December 15, 2006 Hi all,I got this code and something realy queer happens:whem i refer to $DirtyWords as global var and send it into foreach loop i got message that it is not a valid parameter.when i use for loop it forks like a charmany ideas why?[code]$DirtyWords=array('w1','w2','w3','w4');$text="w2 this w3 'man w4 them";CleanLng($text);echo $text;function CleanLng(&$string){ global $DirtyWords;//-->refer to as a global var $SizeDW=sizeof($DirtyWords); $string=explode(" ",$string); $size=sizeof($string); for($i=0;$i<$size;++$i) { /* foreach ($DirtyWords as $Dword)-->***doesnt work*** { if($string[$i]==$Dword) $string[$i]="****"; } */ for ($j=0;$j<$SizeDW;++$j)//->***works fine*** { if($string[$i]==$DirtyWords[$j]) { $string[$i]="****"; break; } } } $string=implode(" ",$string); }[/code] Link to comment https://forums.phpfreaks.com/topic/30813-global-variables-issue/ Share on other sites More sharing options...
fert Posted December 15, 2006 Share Posted December 15, 2006 Sorry didn't read your whole code. Link to comment https://forums.phpfreaks.com/topic/30813-global-variables-issue/#findComment-142070 Share on other sites More sharing options...
emehrkay Posted December 16, 2006 Share Posted December 16, 2006 works fine for me, id dint make any changes. you might want to look into using regex to replace the dirty words though<?php$DirtyWords=array('w1','w2','w3','w4');$text="w2 this w3 'man w4 them";CleanLng($text);echo $text;function CleanLng(&$string){ global $DirtyWords;//-->refer to as a global var $SizeDW=sizeof($DirtyWords); $string=explode(" ",$string); $size=sizeof($string); for($i=0;$i<$size;++$i) { foreach ($DirtyWords as $Dword) { if($string[$i]==$Dword) $string[$i]="****"; } /*for ($j=0;$j<$SizeDW;++$j)//->***works fine*** { if($string[$i]==$DirtyWords[$j]) { $string[$i]="****"; break; } }*/ } $string=implode(" ",$string); }?> Link to comment https://forums.phpfreaks.com/topic/30813-global-variables-issue/#findComment-142175 Share on other sites More sharing options...
weballergy Posted December 16, 2006 Author Share Posted December 16, 2006 i think all my problems (at least for now) stem from the fact that browser somehow ignores the chnages ive made in the code - loads the page from the cashe.someone told me something about shift+f5 ,do you guys know anything about it? Link to comment https://forums.phpfreaks.com/topic/30813-global-variables-issue/#findComment-142316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.