Bottyz Posted October 1, 2010 Share Posted October 1, 2010 Hi all, I'm very new to regex and cannot get my head around all the characters. I've been testing out a few things to work it out but am struggling with one in particular. I've created a news system for my website in php and on the main page you only have a truncated description of each article but with 'read more' links to the full article. The 'read more' links like news.php?article= Where it has the ?article= it has a meaning full seo friendly title such as "new-website" or "news-page-launched" etc.... This link then brings up that full article. My idea is to use a preg_match expression that makes sure all that is in the link is letters and the - symbol. This is to make sure no-one can insert code here and attack the site. Is this a bad idea or can anyone help? Quote Link to comment Share on other sites More sharing options...
Bottyz Posted October 1, 2010 Author Share Posted October 1, 2010 i've figured that this should be ok for use... Can anyone confirm? function validate_art_url($str) { pregmatch('^[a-z]+[\-]*$', $str) ==0; } Quote Link to comment Share on other sites More sharing options...
sasa Posted October 2, 2010 Share Posted October 2, 2010 <?php$test = 'ann+jokn';if(!preg_match('/[^a-z-]/', $test)) echo'OK';else echo'WRONG';?> Quote Link to comment 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.