note 107921 added to function.explode

From: Date: Wed, 14 Mar 2012 22:25:03 +0000
Subject: note 107921 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-186669@lists.php.net to get a copy of this message
Hello, I just wanted to note some behaviours of the explode function, well i am submitting a bunch of urls, one each line and i am using the "\n" (it should be within double quotes) as the delimiter and i am iterating to check for dupe values and always the last value stays unchecked unless i am appending a new line "\n" to the $_POST. Let me demonstrate what i mean(sorry if there is any syntax error i am just writing this on-the-fly): if(isset($_POST['files']) && !empty($_POST['files'])){ $regex = "((http|ftp)+\:\/\/(www.)?(.*)/(.*)(\.)?(.*)?)"; $ls = $_POST['files']; $posts = explode("\n", $ls); //remove duplicates $count = count($posts); for($i=0;$i<$count;$i++){ if($posts[$i]=="") continue; for($j=$i+1;$j<$count;$j++){ if($posts[$j]=="") continue; if((string)$posts[$i] == (string)$posts[$j]){ $posts[$j] = ""; } } } $i=0; $files = array(); foreach($posts as $f ){ if(preg_match($regex,$f,$matches)){ $files[] = $f; $i++; } if($i>=10){ break; } } echo "<pre>"; print_r($files); echo "</pre>"; } submit some urls in this format : http://www.google.com/admin.db http://www.google.com/admin.db[dont hit the "enter" key here] i didn't have much time to look at it in deep so i just appended using javascript the new line : document.getElementById('files').value += "\n"; This way the last dupe value will get deleted too otherwise it wont! ---- Server IP: 69.147.83.197 Probable Submitter: 87.228.162.6 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/107921 Del: integrated -- https://master.php.net/note/delete/107921/integrated Del: useless -- https://master.php.net/note/delete/107921/useless Del: bad code -- https://master.php.net/note/delete/107921/bad+code Del: spam -- https://master.php.net/note/delete/107921/spam Del: non-english -- https://master.php.net/note/delete/107921/non-english Del: in docs -- https://master.php.net/note/delete/107921/in+docs Del: other reasons-- https://master.php.net/note/delete/107921 Reject -- https://master.php.net/note/reject/107921 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186669) next »