point86 Posted March 15, 2007 Share Posted March 15, 2007 Hi, I have a string, retrived via $file = $_GET['filename']; Now, how to I create a condition (preferably a loop) that says 1. read through the string, letter by letter 2. if (letter in question = "X") {do Y} else {do X} Thanks P86 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 15, 2007 Share Posted March 15, 2007 A string can be treated as an array: <?php $file = $_GET['filename']; for ($i=0;$i<strlen($file);$i++) { if ($file[$i] == 'X') { // // do X // } else { // // do Y // } } ?> Ken Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 <?php $file = $_GET['filename']; if (ereg("X", $file)) { // do this }else { //do this } ?> That is one way, not sure if that is the way you want? 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.