Forum Moderators: coopster

Message Too Old, No Replies

Find part of a string

Find part of a string, Left()

         

RedBaron

3:54 pm on May 13, 2005 (gmt 0)

10+ Year Member



I am an ASP guy who has been converting to PHP. Anyway, I'm having a problem figuring out how to find part of a string. What I am trying to do is to list any file that starts with "info". So I've got a while loop that will show all the files, but now I'm trying to figure out how to display only the files that start with "info".

In ASP it would be like this:

If Left(strFileName, 4) = "info" Then
Response.Write(strFileName & "<br>")
End If

Does PHP have a function like this? In the example above it reads the first "4" characters in the string strFileName and compairs it to "info". Any help would be greatly appreciated.

RedBaron

sned

4:29 pm on May 13, 2005 (gmt 0)

10+ Year Member



You might try looking at the strpos function:

[us4.php.net...]

-sned

StupidScript

4:54 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (substr($strFileName,0,4)=="info") {

echo $strFileName."<br />\n";

}

Bookmark: the English version of the PHP manual [php.net]

RedBaron

9:40 pm on May 13, 2005 (gmt 0)

10+ Year Member



Thanks guys! It worked! This forum rulz!

Red Baron