Forum Moderators: coopster

Message Too Old, No Replies

stuck on strpos()

         

electricocean

5:13 am on Sep 6, 2006 (gmt 0)

10+ Year Member



Hi, i am trying to read a file name. i want this code to check if the filename conatains a dash or not and i am trying strpos()

if((strpos($filename, " - ") === false) ¦¦ (strpos($filename, "-") === false)){
$splitby = "test";//do stuff if it does not contain a " - "
}
else{
if(strpos($filename, " - ") === true){
$splitby = " - ";
}
elseif(strpos($filename, "-") === true){
$splitby = "-";
}
}
echo $splitby;

nothing comes up for $splitby. Am I doing this correctly?

thanks,
electricocean

Steerpike

5:30 am on Sep 6, 2006 (gmt 0)

10+ Year Member




Try this:

if(strpos($filename,"-") === false)
{
$splitby="This $filename string does not contain a -";
/* Put extra code here for no dashes. */
}
else
{
$splitby="This $filename string contains a -";
/* Put extra code here for dash being true */
}

echo $splitby;

adb64

6:24 am on Sep 6, 2006 (gmt 0)

10+ Year Member



Hi, change your code into:

if((strpos($filename, " - ") === false) ¦¦ (strpos($filename, "-") === false)){
$splitby = "test";//do stuff if it does not contain a " - "
}
else{
if(strpos($filename, " - ")!== false){
$splitby = " - ";
}
elseif(strpos($filename, "-")!== false){
$splitby = "-";
}
}
echo $splitby;