PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Sep 27, 2009 10:07 pm
If you create a function that can "reject" URLs then you can use
array_filter to remove bad URLs from your array.
(Could modify the regex but my opinion would be not to.)
soul_fly
Forum Newbie
Posts: 22 Joined: Mon Aug 24, 2009 2:24 pm
Post
by soul_fly » Sun Sep 27, 2009 10:10 pm
tasairis wrote: If you create a function that can "reject" URLs then you can use
array_filter to remove bad URLs from your array.
(Could modify the regex but my opinion would be not to.)
I don't want to modify my regex either. Array filter is good idea. Thanks for your great hint.
My other folks, any other better idea, plz let me know also
soul_fly
Forum Newbie
Posts: 22 Joined: Mon Aug 24, 2009 2:24 pm
Post
by soul_fly » Mon Sep 28, 2009 12:29 pm
knock knock. any volunteer to solve this prob?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Sep 28, 2009 3:18 pm
tasairis wrote: If you create a function that can "reject" URLs
That was a hint. Have you created that function yet? It takes a URL as a string and returns true or false if the URL should be kept.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Sep 28, 2009 3:22 pm
To add to tasairis, you can specify a callback function to array_filter() to handle your "logic" and remove the appropriate array elements.
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Sep 29, 2009 7:13 am
hey u can do it like this
Code: Select all
<?
function url($var) {
if(strstr($var, "image"))
return false;
else
return true;
}
$array1 = array("www.dev.com/hello.php", "www.dev.com/image/hello.jpg","www.dev.com/image/mayank.jpg");
print_r(array_filter($array1, "url"));
?>