briedis Posted March 16, 2008 Report Share Posted March 16, 2008 Urbos caur googli, bet nespēju neko sameklēt prātīgu... Tātad, jautājums: Vai iespējams apstrādāt $_GET mainīgos "pa tiešo"? Nu piem., caur GET tiek nodots mainīgais "id" ar saturu "teksts/./". Vai iespējams uztaisīt str_replace un aizstāt "/" ar neko, lai vēlāk skriptā (glob.var=on) izsaucot $id tas vairs nesaturētu "/"? Mēģināju ar norādēm: foreach($_GET as &$item) { $item = str_replace("/","",$item); } ja izsauc $_GET['mainigais'] ir ok, bet ja izsauc $mainigais, tad rādās tas sākotnējais variants ar "/". Ir idejas? Link to comment Share on other sites More sharing options...
bubu Posted March 16, 2008 Report Share Posted March 16, 2008 Tad "neizsauc" $mainigais. Raksti visur $_GET['mainigais'] un nav problēmu. register_globals nav labi lietot. Link to comment Share on other sites More sharing options...
marrtins Posted March 17, 2008 Report Share Posted March 17, 2008 register_globals = bad, mkei? (izņemot gadījumus, kad zina ko dara)? foreach($_GET as &$item) { $item = str_replace("/","",$item); $$item = $item; } Link to comment Share on other sites More sharing options...
elfz Posted March 17, 2008 Report Share Posted March 17, 2008 pirms-php5, un vispār, lasāmāk, foreach($_GET as $k=>$v) { $_GET[$k] = do_something_with($v); } Link to comment Share on other sites More sharing options...
andrisp Posted March 17, 2008 Report Share Posted March 17, 2008 (edited) elfz, kāpēc pirms php5 ? Edited March 17, 2008 by andrisp Link to comment Share on other sites More sharing options...
briedis Posted March 17, 2008 Author Report Share Posted March 17, 2008 Ok, es zinu, ka register_globals bad, bet lapa ir uztaisīta sen, un pārrakstīt visus parastos uz $_GET būtu murgs... Link to comment Share on other sites More sharing options...
andrisp Posted March 17, 2008 Report Share Posted March 17, 2008 Varbūt tad tev noder extract() Link to comment Share on other sites More sharing options...
bubu Posted March 17, 2008 Report Share Posted March 17, 2008 andrisp: tāpēc, ka php4 nevarēja lietot referencei foreach cikla konstrukcijā. Link to comment Share on other sites More sharing options...
indoom Posted March 17, 2008 Report Share Posted March 17, 2008 Varētu jau izlīdzēties arī ar array_map http://lv.php.net/manual/en/function.array-map.php function repl($item) { return str_replace('/','',$item); } $_GET = array_map('repl',$_GET); Link to comment Share on other sites More sharing options...
Recommended Posts