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 Link to comment https://forums.phpfreaks.com/topic/42893-read-through-string-and-extract/ 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 Link to comment https://forums.phpfreaks.com/topic/42893-read-through-string-and-extract/#findComment-208323 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? Link to comment https://forums.phpfreaks.com/topic/42893-read-through-string-and-extract/#findComment-208324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.