if variable contains '..'

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

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

if variable contains '..'

Post by phice »

Looking for any function that will search a string for 2 dots (..), and if the dots are inside the string, then it will result in an error.

[need more information? just ask]
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

if(strstr($string, "..")){
// ERROR
}
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

alternatively:

if (ereg('\.\.', $string)) {
// Erro
}
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you don't need more complicated pattern matching then ereg() is uneccessary. Also strpos() may be a better function to use than strstr() for this particular test:
http://www.php.net/manual/en/function.strpos.php
http://www.php.net/manual/en/function.strstr.php

Mac
Post Reply