EchoFool Posted October 8, 2010 Share Posted October 8, 2010 Which is most efficient for finding a string within a string? Eregi or strpos? Currently im using Eregi to check a string again an array of blocked words and retrun true if one is present. But it seems i can do it also with strpos... so which is best function to use ? Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/ Share on other sites More sharing options...
trq Posted October 8, 2010 Share Posted October 8, 2010 unless you need to match patterns you should be using strpos. Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120092 Share on other sites More sharing options...
rwwd Posted October 8, 2010 Share Posted October 8, 2010 Well not Eregi as it is deprecated as a function since PHP 5.3.0 So preg or strpos would really be the question, and my answer to that is: strpos would be easier as there are no regex patterns to work out, BUT preg_ once you have a handle on the way patterns work is a really handy thing to have grasped, the only drawback is there is more load on the parser when you use preg_ functions. Rw Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120105 Share on other sites More sharing options...
EchoFool Posted October 8, 2010 Author Share Posted October 8, 2010 Okay one final question.. I want to also check for links - thing is, links can vary in terms of how you type them out..and the website name could be anything (basically i'd use a wildcard) but can strpos detect what is and what is not a link ? Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120219 Share on other sites More sharing options...
salathe Posted October 8, 2010 Share Posted October 8, 2010 No, strpos won't match "wildcards" if that is what you are trying to ask. Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120250 Share on other sites More sharing options...
EchoFool Posted October 8, 2010 Author Share Posted October 8, 2010 oh okay - damn Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120252 Share on other sites More sharing options...
rwwd Posted October 8, 2010 Share Posted October 8, 2010 oh okay - damn Preg_ will be your new best friend for that then ;-p Show us an example of a link (exemplified) so that the bod's in here can advise a solution. Rw Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120265 Share on other sites More sharing options...
EchoFool Posted October 8, 2010 Author Share Posted October 8, 2010 Well the links getting spammed are in these formats: (obviously its not really google links but this is example) www.google.com google.com http://google.com http://www.google.com some have IPs in the urls and some have .net / .co.uk etc Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120273 Share on other sites More sharing options...
chmpdog Posted October 8, 2010 Share Posted October 8, 2010 you could have the script flag any post with a website suffix (.com, .org, ect. ) so you can check if it's spam Quote Link to comment https://forums.phpfreaks.com/topic/215396-eregi-or-strpos/#findComment-1120299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.